2016-12-06 46 views
0

閃亮/閃爍面板的新功能。單個複選框組的多個「標籤」

我有一系列的選項,我希望用戶能夠選擇一個或多個。 checkboxGroupInput完成這項工作,但這意味着我只能爲所有選項使用一個標籤。我想要的是能夠標記我的複選框的子集,但將選定的選項作爲單個變量傳遞給服務器。例如,假設我想顯示按類型分組的管絃樂器(風,黃銅......);例如,我想要顯示按類型(風,黃銅等)分組的管絃樂器。

library(shinydashboard) 

    dashboardPage(
     dashboardHeader(title = 'My Orchestra'), 

     dashboardSidebar(
     sidebarMenu() 
     ), 

     dashboardBody(
     fluidRow(
      box(
      checkboxGroupInput("my_orchestra", 
           label = "String", 
           choices = c("Violin" = "Violin", "Cello" = "Cello"), 
           inline = T 
           ), 

      checkboxGroupInput("my_orchestra", 
           label = "Woodwind", 
           choices = c("Bassoon" = "Bassoon", "Flute" = "Flute"), 
           inline = T 
           ), 

      checkboxGroupInput("my_orchestra", 
           label = "Brass", 
           choices = c("Trumpet" = "Trumpet", "Sax" = "Sax"), 
           inline = T 
           ) 
      )) 
     ) 
    ) 

無論哪個選項選中,我想選擇在server.R可訪問爲input$my_orchestra。正如你上面看到的,我試圖通過命名所有的checkboxgroup'my_orchestra'來做到這一點,這是行不通的。有沒有人有辦法做到這一點?

+0

你想要什麼,他們的方式你想要它,因爲那些都是獨一無二的'你不能這樣做divs'和他們必須有唯一的ID –

回答

1

你也許可以內reactiveValues包裝你的選擇,然後用它作爲v$my_orchestra像我一樣:

library(shiny) 
library(shinydashboard) 

ui <- dashboardPage(
    dashboardHeader(title = 'My Orchestra'), 

    dashboardSidebar(
    sidebarMenu() 
), 

    dashboardBody(
    fluidRow(
     box(
     checkboxGroupInput("my_orchestra1", 
          label = "String", 
          choices = c("Violin" = "Violin", "Cello" = "Cello"), 
          inline = T), 

     checkboxGroupInput("my_orchestra2", 
          label = "Woodwind", 
          choices = c("Bassoon" = "Bassoon", "Flute" = "Flute"), 
          inline = T), 

     checkboxGroupInput("my_orchestra3", 
          label = "Brass", 
          choices = c("Trumpet" = "Trumpet", "Sax" = "Sax"), 
          inline = T) 
    ), 
     textOutput("Selected") 
    ) 
) 
) 

server <- (function(input, output, session) { 

    v <- reactiveValues() 
    observe({ 
    v$my_orchestra <- c(input$my_orchestra1,input$my_orchestra2,input$my_orchestra3) 
    }) 
    output$Selected <- renderText({v$my_orchestra}) 
}) 

shinyApp(ui, server) 

enter image description here

+1

謝謝豬排!訣竅了。 – mbyvcm