umair durrani
umair durrani

Reputation: 6155

sliderInput in Shiny app in R

I have a simple question for which I haven't find a solution by far.
In ui.R if the app has a sliderInput widget like following:

sliderInput(inputId="frame",label="Frame ID", min=172, max=356, value=172)

How can I specify the min and max values from the data frame in server.R? The data frame in server.R is subsetted when user selects a value from selectInput widget. For each case I want the min and max to change based on a variable in that data frame.

Is there any example? Please help.

Upvotes: 2

Views: 540

Answers (1)

jdharrison
jdharrison

Reputation: 30425

You can use renderUI to create a reactive control:

ui.R

uiOutput("myControl")

server.R

myDf <- reactive({
# code that subsets data.frame based on input[['somevars']]
})


output$myControl <- renderUI({
  mydataframe <- myDf()
  myVar <- mydataframe[, c("appvar")]
  minmax <- range(myVar)
  startVal <- sample(do.call(":", as.list(minmax)),1)
  sliderInput(inputId="frame",label="Frame ID", min=minmax[1], max=minmax[2][, value=startVal)
})

Upvotes: 4

Related Questions