r - 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)
但我收到了这个错误:无法将类“flextable”强制转换为 data.frame
我们怎样才能解决它?一些帮助将不胜感激
解决方案
您不能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)
推荐阅读
- react-native - 为什么 React Native 的样式组件的 npm 安装失败?
- mysql - 从数据库差异生成更新或替换语句
- java - 如何在事件处理程序中“关闭”JMenu - Java
- javascript - 如何使用 requestFullscreen() 方法从全屏显示的元素中显示模态元素?
- c++ - 未知行但恒定列
- reactjs - 在没有额外渲染的情况下设置更改的依赖项的状态(有一个没有额外渲染的加载器)
- vue.js - VueJS - 在其他绑定的定义中重用道具(字段名)
- javascript - Vue.js 从名字和姓氏中获取首字母以显示在头像中
- reactjs - Npm审计问题,不断出错
- android - 使用含税模板价格时,Android Play 控制台的默认价格是否含税?