0
votes

Based on this post: create plots based on radio button selection R Shiny

I want a different plot output depending on which radio option the user selects and adjust the numbers of committees using the slider input.

The slider input doesn't work and I don't realize how to solve the problem. Many thanks for the help!

Here is my code:

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

2 Answers

0
votes

Make sure to add lable to your sliderinput too:

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
votes

There is no need for comma at the end of this line:

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

should be:

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