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

时间:2017-05-17 08:47:20

标签: r shiny

基于这篇文章: 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 :(得分: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 :(得分:-1)

此行末尾不需要逗号:

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

应该是:

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