Michele Usuelli
Michele Usuelli

Reputation: 2000

connecting two slider inputs in Shiny

I'm building a shiny app for the Random Forest. The widgets have to define two parameters:

How can I define nTree inside the second widget? Its value depends on the first widget.

Thanks in advance.

Upvotes: 2

Views: 2356

Answers (1)

Pork Chop
Pork Chop

Reputation: 29387

You can make the slider dynamically like so:

library(shiny)

ui =(pageWithSidebar(
  headerPanel("Test Shiny App"),
  sidebarPanel(
    sliderInput("nTree", "Number of trees", min = 1, max = 1000, value = 10),
    #display dynamic UI
    uiOutput("iTree")),
  mainPanel()
))

server = function(input, output, session){
  #make dynamic slider
  output$iTree <- renderUI({
    sliderInput("iTree", "Tree to visualise", min=1, max=input$nTree, value=10)
  })
}
runApp(list(ui = ui, server = server))

Upvotes: 7

Related Questions