Shiny 中 table 输出的问题
Trouble with table output in Shiny
这是我的数据集
我想用 flextable 过滤 Shiny 中的产品,得到这样的结果:
这是我的代码:
library(shiny)
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),
tableOutput("tbl")
)
server <- function(input, output, session) {
output$tbl <- renderTable( {
out <- subset(my_data, product ==input$product)
library(flextable)
flextable(out) # i got error
})
}
shinyApp(ui, server)
但我得到了这个错误:无法将 class ‘"flextable"’ 强制转换为 data.frame
我们该如何解决?一些帮助将不胜感激
您不能将 renderTable
与 flextable
对象一起使用。见 ?renderTable
:
expr: An expression that returns an R object that can be used with
xtable::xtable().
Here 您可以找到有关如何在闪亮的应用程序中使用 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)
这是我的数据集
我想用 flextable 过滤 Shiny 中的产品,得到这样的结果:
这是我的代码:
library(shiny)
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),
tableOutput("tbl")
)
server <- function(input, output, session) {
output$tbl <- renderTable( {
out <- subset(my_data, product ==input$product)
library(flextable)
flextable(out) # i got error
})
}
shinyApp(ui, server)
但我得到了这个错误:无法将 class ‘"flextable"’ 强制转换为 data.frame
我们该如何解决?一些帮助将不胜感激
您不能将 renderTable
与 flextable
对象一起使用。见 ?renderTable
:
expr: An expression that returns an R object that can be used with xtable::xtable().
Here 您可以找到有关如何在闪亮的应用程序中使用 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)