r - updateCheckBoxGroupInput in shiny based on selection of other checkboxes -


my shiny application has multiple tabs. in 1 of tabs have plot output want use create reports in tab. have included checkbox in first tab user select output reporting. in second tab trying update check box group input based on selection of first tab. getting first option selected.

the reproducible code follows: based on ifelse condition:

library(shiny) library(shinydashboard)  ui <- dashboardpage(                    dashboardheader(                        title = "module",titlewidth = 225                    ),                    dashboardsidebar(                        width = 225,                        sidebarmenu(id = "tabs",                                    menuitem("toplines", tabname = "tplines", icon = shiny::icon("dashboard")),                                    menuitem("my monthly reports", tabname = "myweeklyrep", icon = shiny::icon("compass"))                        )),                    dashboardbody(                        tabitems(                            tabitem(                                tabname = "tplines",                                fluidrow(                                    box(                                        checkboxinput(inputid = "inventorytop8metrocheck", "add reports", value = false),                                        width = 6, status = "info", title = "inventory information",                                        div(plotlyoutput("inventorytop8metro"), width = "100%", height = "400px", style = "font-size:80%;")                                    ),                                    box(                                        checkboxinput(inputid = "top15categoriestplinescheck", "add reports", value = false),                                        width = 6, status = "info", title = "top 15 categories",                                        div(plotlyoutput("top15categoriestplines"), style = "font-size:90%")                                    ))),                            tabitem(                                tabname = "myweeklyrep",                                fluidrow(                                    h4("available analysis", align = 'center'),br(),                                    column(width = 12,                                            list(tags$div(align = 'left',                                                          class = 'multicol',                                                          checkboxgroupinput(inputid  = 'analysisselector',                                                                             label = "select analysis:",                                                                            choices  = "",                                                                            selected = "",                                                                            inline   = false)))                                    ))))))  server <- function(session,input,output){     observe({             updatecheckboxgroupinput(session, inputid = "analysisselector", label = "", choices =                                           ifelse(!is.null(input$top15categoriestplinescheck) || length(input$top15categoriestplinescheck) != 0, "inventory top 8 metros",                                             ifelse(!is.null(input$inventorytop8metrocheck) || length(input$inventorytop8metrocheck) != 0, "top 15 categories - topline", "no selection")),                                      selected = "",inline = false)      }) }  shinyapp(ui,server) 

i tried if, else if aren't working. thoughts?

the if, else if conditions:

    updatecheckboxgroupinput(session, inputid = "analysisselector", label = "", choices =                                   if(!is.null(input$top15categoriestplinescheck) || length(input$top15categoriestplinescheck) != 0){                                      "inventory top 8 metros"                                  } else if (!is.null(input$inventorytop8metrocheck) || length(input$inventorytop8metrocheck) != 0){                                      "top 15 categories - topline"                                  } else {                                      return()                                  },                              selected = "",inline = false) 

edit:

i tried following option: renders checkboxes irrespective of whether selected or not.

getlist <- reactive({         if(!is.null(input$top15categoriestplinescheck) & !is.null(input$inventorytop8metrocheck)){             c("top 15 categories - topline","inventory of top 8 metros - topline")         } else if (!is.null(input$top15categoriestplinescheck)){             "abc"         } else if (!is.null(input$inventorytop8metrocheck)){             "def"         } else {             return()         }     })      observe({             updatecheckboxgroupinput(session, inputid = "analysisselector", label = "select analysis:", choices =                                           as.list(getlist()),                                      selected = "",inline = false)                 }) 

this easier handle observeevent explained in documentation of function (see ?observeevent). understand, wraps observe in more intuitive way.

you have pass 2 arguments: event (in case, click on 1 of checkboxgroupinputs) , action perform when event occurs.

the server function becomes:

server <- function(session,input,output){     updateanalysisselector <- function(session) {         choices <- ifelse(input$top15categoriestplinescheck, "inventory top 8 metros",                           ifelse(input$inventorytop8metrocheck, "top 15 categories - topline", "no selection"))         updatecheckboxgroupinput(session,                                   inputid = "analysisselector",                                   label = "select analysis:",                                   choices = choices,                                  selected = "",                                  inline = false)     }    observeevent(input$top15categoriestplinescheck, updateanalysisselector(session))   observeevent(input$inventorytop8metrocheck, updateanalysisselector(session)) } 

i'm sure simplified if ui did not have 2 separate checkbox groups works current implementation.


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -