【发布时间】:2021-10-02 06:13:56
【问题描述】:
我正在创建一个shiny 应用程序,用户可以在其中选择plot 进行查看。我使用this question 作为一种方法,但我收到了一个错误。我该如何解决这个问题?
用户界面
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 = 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)
错误
【问题讨论】: