【问题标题】:Formattable does not render output in ShinyFormattable 不会在 Shiny 中呈现输出
【发布时间】:2019-03-14 11:22:46
【问题描述】:

代码在Rstudio中正常工作,代码是

library(datatable)
library(shiny)
library(magrittr)

datatable(report) %>% formatStyle('status',target = 'row',
            backgroundColor = styleEqual(c("Completed","Over run"), c('lightgreen','red')))

但是,我不知道如何输出这个数据表/格式表?在闪亮。

错误提示:

no applicable method for 'as.htmlwidget' applied to an object of class "c('datatables', 'htmlwidget')"

【问题讨论】:

  • 错误从何而来。请添加更多上下文。

标签: r datatable shiny htmlwidgets


【解决方案1】:

我希望这个小闪亮应用程序能帮助你。由于我没有您的数据框report,因此我将其替换为iris 数据框。所以formatStyle 将寻找Species 列并为它们着色。

在用户界面中,您通过DT::dataTableOutput("YourTableID") 定义输出,在服务器中您定义像output$YourTableID <- DT::renderDataTable({ ... }) 这样的输出,您可以在其中放置代码以生成数据表。

另外,您要查找的库是 DT 而不是 datatable

library(DT)
library(shiny)

report <- iris

ui <- fluidPage(
  DT::dataTableOutput("table")
)

server <- function(input, output, session) {
  output$table <- DT::renderDataTable({
    datatable(report) %>% formatStyle('Species',target = 'row',
                                      backgroundColor = styleEqual(c("setosa","versicolor", "virginica"), 
                                                                   c('lightgreen','red', "yellow")))
  })
}

shinyApp(ui, server)

【讨论】:

    猜你喜欢
    • 2017-09-29
    • 2016-12-05
    • 1970-01-01
    • 2018-12-04
    • 1970-01-01
    • 2020-02-15
    • 2016-09-19
    • 2020-02-12
    • 1970-01-01
    相关资源
    最近更新 更多