Say I have a shiny::sliderInput
:
...
sliderInput("input_1", "Title_1",
min = 1, max = 10, value = 5)
...
Is it possible to reference min
, max
, and/or value
in a different sliderInput
? The use case for this is to make a second a input dependent on the first input. Something to the tune of the minimum of the second input can never be less than the value from input_1
.
Something like (this does not work):
sliderInput("input_2", "Title_2",
min = input_1$value, max = 10, value = input_1$value)
My hunch is this might be possible with renderUI
, but not sure where or how to start?
This is an example of defining a widget in server.R
:
library(shiny)
shiny::runApp(list(
ui = fluidPage(
numericInput("input_2", "select min value", value = 5),
uiOutput("input_1")
),
server = function(input, output) {
output$input_1 <- renderUI({
sliderInput("input_1", "Title_1", min = input$input_2, max = 10, value = 5)
})
}
))
So it is reactive to changes in ui.R
An example of updateSliderInput
in shiny rmd
---
title: "Dependent Inputs"
runtime: shiny
output:
html_document
---
```{r}
sliderInput("n", "n", min=0, max=100, value=1)
sliderInput("n2", "n2", min=0, max=100, value=1)
observe({
updateSliderInput(session, "n", min=input$n2-1, max=input$n2+1, value=input$n2)
})
```
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With