create plots based on radio button selection R Shiny

后端 未结 1 1645
予麋鹿
予麋鹿 2020-12-05 21:48

I\'m trying to create a Shiny App. The user interface UI.R looks just fine but I\'m having issues with server.R. Basically I want a di

相关标签:
1条回答
  • 2020-12-05 22:20

    You can use switch to determine the behaviour based on the selection:

    library(shiny)
    myData <- runif(100)
    plotType <- function(x, type) {
      switch(type,
             A = hist(x),
             B = barplot(x),
             C = pie(x))
    }
    runApp(list(
      ui = bootstrapPage(
        radioButtons("pType", "Choose plot type:",
                     list("A", "B", "C")),
        plotOutput('plot')
      ),
      server = function(input, output) {
        output$plot <- renderPlot({ 
           plotType(myData, input$pType)
        })
      }
    ))
    
    0 讨论(0)
提交回复
热议问题