首页 文章

R基于单选按钮和滑块输入的闪亮图

提问于
浏览
0

根据这篇文章:create plots based on radio button selection R Shiny

我想要一个不同的绘图输出,具体取决于用户选择的无线电选项,并使用滑块输入调整委员会的数量 .

滑块输入不起作用,我没有意识到如何解决问题 . 非常感谢您的帮助!

这是我的代码:

library(shiny)
library(Cubist)    
plotType <- function(x, type, committe) {
        switch(type,
               Cond = dotplot(finalModel, what = "splits"),
               Coeff = dotplot(finalModel, what = "coefs"))
    }
    ui <- shinyUI(fluidPage(
           sidebarLayout(
              sidebarPanel(
                radioButtons(inputId = "ptype", label = "Select the plot", choices = c("Cond", "Coeff")),
                sliderInput(inputId = "commit", min=1, max = 25, value = 2)
             ),
           mainPanel(
                plotOutput("plots"))
    )))

    server <- shinyServer(function(input, output) {
         output$plots <-renderPlot({
            plotType(finalModel, input$ptype, input$commit)

        })
    })


    shinyApp(ui = ui, server = server)

2 回答

  • 0

    一定要将 lable 添加到 sliderinput 中:

    library(shiny)
    plotType <- function(x, type, committe) {
      switch(type,Cond = dotplot(finalModel, what = "splits"),Coeff = dotplot(finalModel, what = "coefs"))
    }
    
    ui <- shinyUI(fluidPage(
      sidebarLayout(
        sidebarPanel(
          radioButtons(inputId = "ptype", label = "Select the plot", choices = c("Cond", "Coeff")),
          sliderInput(inputId = "commit","",  min=1, max = 25, value = 2)
        ),
        mainPanel(
          plotOutput("plots"))
      )))
    
    server <- shinyServer(function(input, output) {
      output$plots <- renderPlot({
        plotType(finalModel, input$ptype, input$commit)
      })
    })
    
    
    shinyApp(ui = ui, server = server)
    
  • -1

    此行末尾不需要逗号:

    sliderInput(inputId = "commit", min=1, max = 25, value = 2),
    

    应该:

    sliderInput(inputId = "commit", min=1, max = 25, value = 2)
    

相关问题