【发布时间】:2021-02-13 06:32:04
【问题描述】:
寻求一些帮助,将条件格式添加到 R Shiny 中的 renderTable。我使用renderTable 而不是DT 包renderDataTable 因为我有一个超过400 列的数据框。 DT 渲染时卡住了,但 renderTable 似乎工作得很快。
这是一个例子:
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)
}
根据numFruit 中的值,更新 按钮会将值>= input$numFruit 的所有单元格的背景变为绿色。
【问题讨论】:
标签: r shiny conditional-formatting