Hide UI elements but store values


#1

Hi.

I have a checkboxGroupInput ui element as a Male and Female filter in shinydashboard which by default are both selected. I wish that uiOutput("genderGroup") be hidden from the dashboard but make the values in output$genderGroup available as arguments in functions.

The reason for this is the dashboard is a template for multiple projects. Some projects will require filtering by gender others won’t though the gender field is still included in the data. As a number of functions will be the same across projects, rather than having to rewrite them on a project by project basis I wonder if I could just hide the ui element and pass the defaults to the functions when hidden. On other projects requiring the filter, I can unhide them and let the user select.

I’ve tried wrapping uiOutput("genderGroup") in hidden() but it also hides the values and the dashboard hangs when required by a function.

Any tips
Andrew


#2

did you try to use req to check for missing input?


#3

I'm pretty sure you can wrap the uiOutput in a conditionalPanel() where the condition is 'false'. I haven't used this myself and am unsure what a good practice is, but it seems to work.

conditionalPanel('false', uiOutput("genderGroup"))

#4

You can store the values of your inputs in reactive variables, so they will be available even if the inputs are hidden.
To hide the inputs you can set the return value of the uiOutput to NULL if a project is chosen that doesn't require filtering by gender and to the input elements if another project is chosen.