r - Selecting all the check-boxes at once in Shiny -


i know how select check-boxes @ once. in code have 5 check-boxes.

server <- function(input, output) {   output$distplot <- renderplot({     hist(rnorm(input$obs), col = 'darkgray', border = 'white')   }) }  ui <- fluidpage(   sidebarlayout(     sidebarpanel(       sliderinput("obs", "number of observations:", min = 10, max = 500, value = 100),       checkboxinput("checkbox1", label = "meansnr", value= false),       checkboxinput("checkbox2", label = "t-statistics", value = false),       checkboxinput("checkbox3", label = "adjusted p-value", value = false),       checkboxinput("checkbox4", label = "log-odds", value = false),       checkboxinput("checkbox5", label = "all", value = false)),     mainpanel(plotoutput("distplot"))   ) )  shinyapp(ui = ui, server = server) 

i know how make work

1) if user selects fifth check-box all, should automatically select check-boxes. on uncheck, should deselect checkboxes.

2 ) if user selects first 4 check-boxes, should select fifth 1 all check-box too.

for condition 1) , screen should enter image description here

this isn't elegant jorel's answer, it's solution uses pure shiny package code.

    library(shiny) #* make sure include session argument in order use update functions server <- function(input, output, session) {    output$distplot <- renderplot({     hist(rnorm(input$obs), col = 'darkgray', border = 'white')   })    #* observer update checkboxes 1 - 4 true whenever checkbox 5 true   observeevent(     eventexpr = input$checkbox5,     handlerexpr =      {       if (input$checkbox5)       lapply(paste0("checkbox", 1:4),              function(x)              {                updatecheckboxinput(session, x, value = input$checkbox5)              }       )     }   )    #* observer set checkbox 5 false whenever of checkbox 1-4 false   lapply(paste0("checkbox", 1:4),          function(x)            {             observeevent(               eventexpr = input[[x]],                handlerexpr =                {                 if (!input[[x]]) updatecheckboxinput(session, "checkbox5", value = false)               }             )           }   )  }  ui <- fluidpage(   sidebarlayout(     sidebarpanel(       sliderinput("obs", "number of observations:", min = 10, max = 500, value = 100),       checkboxinput("checkbox1", label = "meansnr", value= false),       checkboxinput("checkbox2", label = "t-statistics", value = false),       checkboxinput("checkbox3", label = "adjusted p-value", value = false),       checkboxinput("checkbox4", label = "log-odds", value = false),       checkboxinput("checkbox5", label = "all", value = false)     ),     mainpanel(plotoutput("distplot"))   ) )  shinyapp(ui = ui, server = server) 

some follow , recommendations

i spent little time trying application you've specified, honestly, felt pretty unnatural (and wasn't working particularly well).

  1. in checkbox, if check "all", implies wish check boxes, don't think unselecting "all" implies unselecting of boxes.
  2. stemming 1), you're trying have 1 control 2 different things, can open door confusion.

so here's recommendation: user 4 checkboxes , 2 buttons. 2 buttons control if select or unselect of boxes, , act independently.

library(shiny) #* make sure include session argument in order use update functions server <- function(input, output, session) {    output$distplot <- renderplot({     hist(rnorm(input$obs), col = 'darkgray', border = 'white')   })    #* observer update checkboxes 1 - 4 true whenever selectall clicked   observeevent(     eventexpr = input$selectall,     handlerexpr =      {       lapply(paste0("checkbox", 1:4),              function(x)              {                  updatecheckboxinput(session = session,                                       inputid = x,                                       value = true)              }       )     }   )    #* observer update checkboxes 1 - 4 false whenever deselectall clicked   observeevent(     eventexpr = input$deselectall,     handlerexpr =      {       lapply(paste0("checkbox", 1:4),              function(x)              {                  updatecheckboxinput(session = session,                                       inputid = x,                                       value = false)              }       )     }   )   }  ui <- fluidpage(   sidebarlayout(     sidebarpanel(       sliderinput("obs", "number of observations:", min = 10, max = 500, value = 100),       checkboxinput("checkbox1", label = "meansnr", value= false),       checkboxinput("checkbox2", label = "t-statistics", value = false),       checkboxinput("checkbox3", label = "adjusted p-value", value = false),       checkboxinput("checkbox4", label = "log-odds", value = false),       actionbutton("selectall", label = "select all"),       actionbutton("deselectall", label = "deselect all")     ),     mainpanel(plotoutput("distplot"))   ) )  shinyapp(ui = ui, server = server) 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -