2017-04-11 94 views
0

我有以下閃亮小閃亮的應用程序。我創建了全選動作按鈕。那麼當我點擊「全選」按鈕時,如何選擇全部(A1,...,C2)?動作按鈕與選擇所有在Rstudio的閃亮工具

#ui script 
library(shiny) 
fluidPage(
    selectizeInput("select", "Select multiple", multiple = T, 
    choices = c("A1", "A2", "B1", "B2", "C1", "C2")), 
    actionButton("selectall", "Select all:") 
) 
#server script 
server <- function(input, output){ 
} 

回答

0

這是你想要的嗎?

rm(list = ls()) 
library(shiny) 
mychoices <- c("A1", "A2", "B1", "B2", "C1", "C2") 

ui <- fluidPage(
    selectInput("campaigns", "Choose campaign(s):", multiple = T, choices = mychoices), 
    actionButton("selectall", "Select all:") 
) 
server <- function(input, output, session) { 
    observeEvent(input$selectall,{ 
    if (input$selectall%%2 == 0){ 
     updateSelectInput(session,"campaigns","Choose campaign(s):",choices=mychoices) 
    } 
    else{ 
     updateSelectInput(session,"campaigns","Choose campaign(s):",choices=mychoices,selected=mychoices) 
    } 
    }) 
} 
runApp(list(ui = ui, server = server)) 
+0

是的!謝謝。 – Sumeda