r - 使用仪表板中的下拉菜单切换报告时出现未知列错误
问题描述
此错误出现一秒钟然后消失,但我能够看到报告。我有一个演示要展示。请帮我。谢谢你。
library(shiny)
library(DT)
library(leaflet)
library(dplyr)
ui <- fluidPage(
selectInput(
"FILE",
"Select the Report:",
choices = c("tbl1","tbl2","tbl3")),
checkboxGroupInput(
"col_n",
"Columns to display:",
choices = c()
),
DT::dataTableOutput("table_data")
)
server <- function(input, output,session) {
df <- reactive ({
switch(input$FILE,
"tbl1" = iris,
"tbl2" = mtcars,
"tbl3" = faithful
)
})
observeEvent(input$FILE,{
req(df())
updateCheckboxGroupInput(
session,
"col_n",
choices = colnames(df()),
selected = colnames(df())
)
})
output$table_data <- DT::renderDataTable({
req(input$col_n)
DT::datatable(
df() %>% select_at(input$col_n),
rownames = FALSE)
})
}
shinyApp(ui, server)
解决方案
您需要这样做,isolate(df())
因为应用程序尝试再次进行子集化而不更改列名值,尽管它们已经消失了。
output$table_data <- DT::renderDataTable({
isolate(df()) %>% select_at(input$col_n)},
rownames = FALSE
)
应用程序:
library(shiny)
library(DT)
library(dplyr)
ui <- fluidPage(
selectInput(
"FILE",
"Select the Report:",
choices = c("tbl1","tbl2","tbl3")),
checkboxGroupInput(
"col_n",
"Columns to display:",
choices = c()
),
DT::dataTableOutput("table_data")
)
server <- function(input, output,session) {
df <- reactive ({
switch(input$FILE,
"tbl1" = iris,
"tbl2" = mtcars,
"tbl3" = faithful
)
})
observeEvent(input$FILE,{
req(df())
updateCheckboxGroupInput(
session,
"col_n",
choices = colnames(df()),
selected = colnames(df())
)
})
output$table_data <- DT::renderDataTable({
isolate(df()) %>% select_at(input$col_n)},
rownames = FALSE
)
}
shinyApp(ui, server)
推荐阅读
- c++ - 在 C++ 类上调用 void 函数
- node.js - 在dynamodb中获取单个alexa响应的时间戳
- python - 尝试在 while 循环中重新定义变量时,NoneType 对象不可调用
- javascript - 如何在回调方法中保留“this”?
- python - SQLAlchemy 子查询获取 AttributeError:“查询”对象没有属性“is_clause_element”
- docker - -v 从 docker 容器中删除所有数据
- c# - 从外部类传递双重形式
- python - 图断开连接 - keras
- java - 求解三次公式 Java
- mysql - mysql用if语句替换成