Looking for some help adding conditional formatting to a renderTable
in R Shiny. I'm using renderTable
instead of DT
package renderDataTable
because I have a dataframe of over 400 columns. DT
was choking on the rendering, but renderTable
seems to work very quickly.
Here is an example:
if (interactive()) {
library(DT)
fruit <- c("Apple", "Orange", "Pear", "Banana")
num <- c(54, 25, 51, 32)
Oct2020 <- c(10, 15, 20, 25)
Nov2020 <- c(5, 7, 10, 15)
Dec2020 <- c(7, 9, 12, 17)
Jan2021 <- c(6, 9, 2, 0)
Feb2021 <- c(15, 30, 12, 2)
Mar2021 <- c(6, 7, 8, 10)
data <- data.frame(fruit, num, Oct2020, Nov2020, Dec2020, Jan2021, Feb2021, Mar2021)
ui <- fluidPage(
fluidRow(
column(width = 1, numericInput("numFruit", "Number of Fruit", value = 10)),
column(width = 1, div(style = "margin-top: 25px", actionButton("btnUpdate", "Update")))
),
fluidRow(
div(style = 'height: 200px; width: 500px; overflow: scroll; font-size: 90%', align = "left", tableOutput("dt_Fruit"))
)
)
server <- function(input, output, session) {
output$dt_Fruit <- renderTable(data, striped = TRUE, hover = TRUE, bordered = TRUE)
}
shinyApp(ui, server)
}
Depending on the value in numFruit
, the Update button will shade the background of all the cells green where the value is >= input$numFruit
.