2
votes

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

  • the number of trees, between 1 and 1000

    sliderInput("nTree", "Number of trees", min = 1, max = 100, value = 10)

  • a tree to visualise, between 1 and the number of trees (input$nTree) that depends on the first widget

    sliderInput("iTree", "Tree to visualise", min = 1, max = nTree, value = 10)

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

Thanks in advance.

1

1 Answers

7
votes

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))