Home > Mobile >  Select plot from a dropdown menu in RShiny
Select plot from a dropdown menu in RShiny

Time:10-03

I am creating a shiny app in which the user can select the plot to view. I used enter image description here

CodePudding user response:

Here's a way -

library(shiny)
library(shinydashboard)
library(shinythemes)

ui =   navbarPage("Project ", theme = shinytheme("cyborg"),
                  uiOutput("all"),
                  tabPanel("Plot",
                           icon = icon("chart-area"),
                           sidebarLayout(sidebarPanel(
                             selectInput("Plot", "Please select a plot to view:",
                                         choices = c("Plot-1", "Plot-2")),
                             actionButton("submit", "Submit")),
                             plotOutput(outputId = "Plots",
                                        width = "1024px",
                                        height = "768px")
                           )))

server = function(input, output, session) {
  
  observeEvent(input$submit,{

      Plot1 = ggplot(midwest, aes(x=area, y=poptotal))  
        geom_point()
      Plot2 =  ggplot(midwest, aes(x=area, y=poptotal))   geom_point()   
        geom_smooth(method="lm")

  output$Plots = renderPlot({
    switch(isolate(input$Plot),
           "Plot-1" = Plot1,
           "Plot-2" = Plot2)
  })
  
  })
  

  
  
}

# Run the application 
shinyApp(ui = ui, server = server)
  • Related