shinyapps - Display all the option values using selectInput() in R Shiny -


in case, options states , instead of group of check boxes, have selectinput drop down. triggering logic means of single check box in ui.now, want is, every time click box, states should pre-selected in drop down , user input required in case when check box not clicked. unfortunately, irrespective of whether user has clicked check-box or not, output user selects in drop down i.e. default "all states" not populated pre-selections.

server.r -       observe({     if(input$national>0)     {if (input$national %% 2 == 0){         updateselectinput(session,                         "state",label = h4("select state"),                                                        choices = list("nsw" = "nsw","victoria" = "victoria","sa" = "sa","tasmania" = "tasmania"),                                                                                                                                                          selected = c("nsw","victoria","sa","tasmania"),multiple = true                                                                                   )}       else        {updateselectinput(session,                         "state",                                                         label = h4("select state"),                                                        choices = list("nsw" = "nsw","victoria" = "victoria","sa" = "sa","tasmania" = "tasmania"),                                                                                                                                                          selected = c(),multiple = true                                                                                     )    }} })  

any appreciated , many in advance.

add button in ui.r

actionbutton("selectall", label="select/deselect all") 

in server.r let selectall modify selector input (here call show_vars).

 observe({   if (input$selectall > 0) {     if (input$selectall %% 2 == 0){       updatecheckboxgroupinput(session=session,                                 inputid="show_vars",                                choices = list("carat" = "carat",                                               "cut" = "cut",                                               "color" = "color",                                               "clarity"= "clarity",                                               "depth" = "depth",                                               "table" = "table",                                               "price" = "price",                                               "x" = "x",                                               "y" = "y",                                               "z" = "z"),                                selected = c(names(diamonds)))      } else {       updatecheckboxgroupinput(session=session,                                 inputid="show_vars",                                choices = list("carat" = "carat",                                               "cut" = "cut",                                               "color" = "color",                                               "clarity"= "clarity",                                               "depth" = "depth",                                               "table" = "table",                                               "price" = "price",                                               "x" = "x",                                               "y" = "y",                                               "z" = "z"),                                selected = c())      }} }) 

the mod 2 (%% 2) makes work every second click select all, otherwise defaults second branch can preselect whatever want (or nothing in case).


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -