Formattable有一些简单的选项来格式化表格,例如:
library(shiny)
library(DT)
library(formattable)
df <- formattable(iris, lapply(1:4, function(col){
area(col = col) ~ color_tile("red", "green")稍后可以将其转换为DT数据表
df <- as.datatable(df)对我来说,在RStudion的查看器中查看它的效果非常好。然而,我想以某种方式将其部署为一个闪亮的应用程序。完整代码:
library(DT)
library(shiny)
ui <- fluidPage(
DT::dataTableOutput("table1"))
server <- function(input, output){
df <- formattable(iris, lapply(1:4, function(col){
area(col = col) ~ color_tile("red", "green")
}))
df <- as.datatable(df)
output$table1 <- DT::renderDataTable(DT::datatable(df))
}
shinyApp(ui, server)这不起作用,有什么解决办法吗?我喜欢formattable的条件格式,但也想使用DT提供的一些选项,例如过滤、搜索、colvis等。
要将其部署为formattable,有一个线程:
发布于 2017-07-25 19:54:30
是的,这似乎是可能的,正如here也提到的那样。下面是一些关于如何实现这一点的示例代码:
library(shiny)
library(data.table)
library(formattable)
ui <- fluidPage(
selectInput("input1","Species: ", choices = c("setosa", "versicolor", "virginica")),
DT::dataTableOutput("table1"))
# make a data.table of the iris dataset.
df <- iris
server <- function(input, output){
output$table1 <- DT::renderDataTable( {
my_df <- df[df$Species==input$input1,]
return(as.datatable(formattable(my_df, lapply(1:4, function(col){area(col = col) ~ color_tile("red", "green")}))))
}
)
}
shinyApp(ui, server)https://stackoverflow.com/questions/45302045
复制相似问题