代码之家  ›  专栏  ›  技术社区  ›  Wilcar

允许用户根据复选框GroupInput完成要显示的列列表

  •  1
  • Wilcar  · 技术社区  · 7 年前

    @熊炳金的示例,关于 stack overflow allows the user first to display a full dataset and to second to change the columns to display with a checkboxgroupinpuT.

    我想帮忙做些不同的事情:

    我想要的:

    1. 数据表显示从任意列列表开始(例如: carb , wt , drat of mtars datset ),而不是完整的数据集。
    2. 用户可以使用复选框GroupInput完成要显示的列表。(例如:add vs )。
      1. @雄兵劲示例:

        library(闪亮)
        runapp(列表(
        ui=基本页面(
        选择输入(“选择”,“选择要显示的列”,名称(mtcars),多个=
        是的)。
        h2(“MTCars数据”),
        DataTableOutput(“MyTable”)。
        ),请
        服务器=功能(输入、输出){
        输出$myTable=rendertatable({
        columns=名称(mtcars)
        如果(!为.null(输入$select))。{
        columns=输入$select
        }
        mtcars[,列,drop=false]
        })
        }
        ))
        允许用户首先显示完整的数据集,然后更改要用复选框GroupInput显示的列。

        我想帮忙做些不同的事情:

        我想要的:

        1. 数据表显示以任意列列表开始(例如:carb,请wt,请drat属于mtars datset)而不是完整的数据集。
        2. 用户可以使用复选框GroupInput完成要显示的列表。(例如:添加vs)。

        enter image description here

        @雄兵劲示例:

         library(shiny)
         runApp(list(
         ui = basicPage(
         selectInput("select", "Select columns to display", names(mtcars), multiple = 
         TRUE),
         h2('The mtcars data'),
          dataTableOutput('mytable')
        ),
         server = function(input, output) {
         output$mytable = renderDataTable({
          columns = names(mtcars)
          if (!is.null(input$select)) {
            columns = input$select
          }
          mtcars[,columns,drop=FALSE]
         })
         }
        ))
        
    1 回复  |  直到 7 年前
        1
  •  1
  •   kluu    7 年前

    正如@marc p所建议的,您可以只关注 names(mtcars) 通过提供给 selected 参数。这也有助于排除在 input$select null .

    library(shiny)
    
    ui = basicPage(
      selectInput("select", "Select columns to display", 
                  names(mtcars),
                  selected = names(mtcars)[c(1, 3)], # display 1st and 3rd variables 
                  multiple = TRUE),
      h2('The mtcars data'),
      dataTableOutput('mytable')
    )
    
    server = function(input, output) {
      output$mytable = renderDataTable({
        mtcars[, input$select, drop=FALSE]
      })
    }
    
    shinyApp(ui, server)
    
    推荐文章