Shiny 中的表输出出现问题

Joh*_*ohn 1 dashboard r flextable shiny

这是我的数据集

\n

在此输入图像描述

\n

我想用 flextable 过滤 Shiny 中的产品并得到这样的结果:

\n

在此输入图像描述

\n

这是我的代码:

\n
library(shiny)\n\nmy_data = data.frame(product = rep(c("auto", "boat"),each=2),\n                  year = c("2009", "2011", "2005", "2019"),\n                  price = c("10 000", "20 000", "7 000", "60 000"),\n                  speed = c("220", "250", "70", "140"))\n\n\nui <- fluidPage(\n  selectInput("product", "", choices = my_data$product),\n  tableOutput("tbl")\n)\n\nserver <- function(input, output, session) {\n  output$tbl <- renderTable( {\n    out <- subset(my_data, product ==input$product)\n    library(flextable)\n    flextable(out) # i got error\n  })\n}\n\nshinyApp(ui, server)\n
Run Code Online (Sandbox Code Playgroud)\n

但我收到此错误:无法将类 \xe2\x80\x98"flextable"\xe2\x80\x99 强制到 data.frame

\n

我们该如何解决它?一些帮助将不胜感激

\n

ism*_*gal 5

renderTable您不能与对象一起使用flextable。看?renderTable

expr:返回可与 xtable::xtable() 一起使用的 R 对象的表达式。

在这里flextable您可以找到有关如何在闪亮的应用程序中使用的教程。

请检查以下内容:

library(shiny)
library(flextable)

my_data = data.frame(product = rep(c("auto", "boat"),each=2),
                     year = c("2009", "2011", "2005", "2019"),
                     price = c("10 000", "20 000", "7 000", "60 000"),
                     speed = c("220", "250", "70", "140"))


ui <- fluidPage(
  selectInput("product", "", choices = my_data$product),
  uiOutput("tbl")
)

server <- function(input, output, session) {
  output$tbl <- renderUI( {
    out <- subset(my_data, product ==input$product)
    library(flextable)
    htmltools_value((flextable(out)))
  })
}

shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud)