Hi, the solution without ggplot2
, but with the ReporteRs
package, see, for example, the application below, the main FlexTable
function:
EDIT: yes, you can put shiny widgets in an HTML table, here is an example with checkboxInput
for selecting rows:
library(ReporteRs) library(shiny) mtcars = mtcars[1:6, ] runApp(list( ui = pageWithSidebar( headerPanel = headerPanel("FlexTable"), sidebarPanel = sidebarPanel( selectInput(inputId = "colCol", label = "Col to color", choices = c("None", colnames(mtcars)), selected = "None"), selectizeInput(inputId = "rowCol", label = "Row to color", choices = rownames(mtcars), multiple = TRUE, options = list(placeholder = 'None', onInitialize = I('function() { this.setValue(""); }'))) ), mainPanel = mainPanel( uiOutput(outputId = "tableau"), br(), verbatimTextOutput(outputId = "row_select"), uiOutput(outputId = "car_selected") ) ), server = function(input, output, session) { output$tableau <- renderUI({ # here we add check box into the table: it create 6 new input widgets mtcars$choice = unlist(lapply(1:nrow(mtcars), FUN = function(x) { paste(capture.output(checkboxInput(inputId = paste0("row", x), label = paste("Row", x), value = TRUE)), collapse = " ") })) tabl = FlexTable( mtcars, # tune the header and the cells header.cell.props = cellProperties( background.color = "#003366", padding = 5 ), body.cell.props = cellProperties( padding = 5 ), header.text.props = textBold( color = "white" ), add.rownames = TRUE ) tabl = setZebraStyle( tabl, odd = "#DDDDDD", even = "#FFFFFF" ) # set a column color if (input$colCol != "None") { tabl = setColumnsColors( tabl, j=which(names(mtcars) %in% input$colCol ), colors = "orange" ) } # set a row color if (!is.null(input$rowCol)) { tabl = setRowsColors( tabl, i=which(rownames(mtcars) %in% input$rowCol ), colors = "#3ADF00" ) } return(HTML(as.html(tabl))) }) output$row_select <- renderPrint({ # you can use the input created into the table like others c("row1" = input$row1, "row2" = input$row2, "row3" = input$row3, "row4" = input$row4, "row5" = input$row5, "row6" = input$row6) }) output$car_selected <- renderUI({ # if you have more than 6 rows it could be convenient selected = eval(parse(text = paste("c(", paste(paste0("input$row", 1:6), collapse =", "), ")"))) HTML(paste0("You have selected the following cars : ", paste(rownames(mtcars)[selected], collapse = ", "))) }) } ))
How to do it (with a checkbox):
