【发布时间】:2020-01-26 04:52:46
【问题描述】:
我正在尝试使用dataTableProxy 更新列的backgroundColor。但是,我不确定如何正确处理列名。这是一个例子:
library(shiny)
library(DT)
ui <- fluidPage(
fluidRow(
DT::dataTableOutput("myplot")
)
)
server <- function(input, output) {
output$myplot <- DT::renderDataTable({
datatable(as.data.frame(rnorm(5))) %>%
formatStyle(1, backgroundColor = 'red')
})
proxy <- DT::dataTableProxy("myplot")
mycolors <- c("red", "green", "blue")
observe({
invalidateLater(1000)
proxy %>% replaceData(as.data.frame(rnorm(5)))
# proxy %>% replaceData(as.data.frame(rnorm(5))) %>%
# formatStyle(1, backgroundColor = sample(mycolors, 1))
})
}
shinyApp(ui = ui, server = server)
即使数字按预期更新,我也无法让formatStyle 工作(注释掉的代码)。它一直显示以下错误:
Warning: Error in !: invalid argument type 56: name2int
这是我在调用formatStyle 时使用"rnorm(5)" 作为列时遇到的错误。
Warning: Error in name2int: You specified the columns: rnorm(5), but the column names of the data are 57: stop
使用dataTableProxy 时引用列的正确方法是什么?
【问题讨论】:
标签: r shiny datatables dt