connecting two slider inputs in Shiny

我怕爱的太早我们不能终老 提交于 2020-01-24 23:18:27

问题


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:


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


来源:https://stackoverflow.com/questions/27448065/connecting-two-slider-inputs-in-shiny

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!