【发布时间】:2019-03-28 10:34:42
【问题描述】:
我无法在 Shiny 中同时使用 radioButtons 和 selectInput 函数来选择/取消选择 mtcars 数据集的不同列。 有人可以帮助我,因为我从过去 2 天开始就一直坚持下去。 我将不胜感激。
问候
data(mtcars)
#Ui
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
column(width = 10,
radioButtons(inputId="variables", label="Select variables:",
choices = c("All","mpg","cyl","disp"),
selected = "All", inline = TRUE )),
column(width = 10,
selectInput(inputId = "level", label = "Choose Variables to
display", multiple = TRUE, choices = names(mtcars)[4:11]))),
mainPanel (
h2("mtcars Dashboard"),
DT::dataTableOutput("table"))))
#server
server<-function(input, output) {
output$table <- DT::renderDataTable(DT::datatable(filter='top', editable = TRUE, caption = 'mtcars',
{
data <- mtcars
data<-data[,input$variables,drop=FALSE]
column = names(mtcars)
if (!is.null(input$level)) {
column = input$level }
data
})) }
shinyApp(ui = ui, server = server)
【问题讨论】:
-
Error in DT::datatable: unused argument (editable = TRUE)您需要从数据表中删除editable。您还需要以不同的方式处理All,因为没有名为“All”的列 -
Suliman 能否请您更新我的查询(如果可能)
-
你打算如何在同一个查询中使用 radioButtons 和 selectInput。
-
你可以使用其他一些功能,目的是有两个不同的功能来选择/取消选择列
-
非常感谢,这两个功能可以应用在一张单表上吗?我不想要 2 个单独的表格。请指导。问候
标签: r drop-down-menu datatables shiny dashboard