I am creating a shiny
app in which the user can select the plot
to view. I used this question as an approach, but I am getting an error. How can I fix this?
UI
library(shiny)
library(shinydashboard)
library(shinythemes)
library(tidyverse)
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")),
submitButton("Submit")),
plotOutput(outputId = "Plots",
width = "1024px",
height = "768px")
)))
Server
server = function(input, output, session) {
data = eventReactive(input$Plot,{
switch(input$Plot,
"Plot-1" = Plot1,
"Plot-1" = Plot2)
})
output$Plots = renderPlot({
data("midwest", package = "ggplot2") # Sample data
Plot1 = ggplot(midwest, aes(x=area, y=poptotal)) +
geom_point()
Plot2 = ggplot(midwest, aes(x=area, y=poptotal)) + geom_point() +
geom_smooth(method="lm")
})
}
# Run the application
shinyApp(ui = ui, server = server)
Error