In my Shiny app I have a tabPanel Second page in which the user inputs some values e.g value1, value2, value3. Then I have another tabPanel First page, it consists of checkboxGroupInput in which the user chooses which values should be used for calculating the minimum of inserted values in tabPanel Second page. Is it possible that this min of values is used as initial value of another NumericInput in tabpanel Second page?
Here I have an example for three choices, but actually I have 6, so segregating choices with if & ifelse (like here: R shiny : checkboxGroupInput value ) would be a really long way. Is there a smoother way?
Thank you for your answers.
E.g.
ui<- navbarPage(title=div("Problem"),
tabPanel (title="First page",
fluidRow(column(2,numericInput("value", "Insert a value", value = **min(of selected values)**, min = 0, max=5, step=0.0001),
checkboxGroupInput("variable", "Inital values expressed as min of:",
choices=c("House",
"Apartment",
"Car"
))))),
tabPanel (title="Second page", fluidRow(column(2,
numericInput("value1", "House", value =0.02, min = 0, max=5, step=0.0001),
numericInput("value2", "Apartment", value =1, min = 0, max=5, step=0.0001),
numericInput("value3", "Car", value =0.15,min = 0, max=5, step=0.0001)))))
server <- function(input, output) { }
shinyApp(ui, server)
You can have this functionality with a following example app.R
If you want an input element to react to the previous user input, it usually has to be rendered with
renderUI
anduiOutput
. The needed value is extracted in a reactive block, and further directed to the input element inside therenderUI
.You can skip the endless-feeling if...else by using the
checkboxGroupInput
result as numeric index for thenumericInput
vector, just make sure you use the same order in the vector andcheckboxGroupInput
.