【发布时间】:2020-10-06 14:52:53
【问题描述】:
给定一个带有 ggplot2 绘图的闪亮应用程序,您将如何根据用户输入更新用于构建绘图的 x 和 y 变量?
代码:
library(shiny)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
selectInput("xcol",
"X:",
choices = c("Sepal.Length", "Sepal.Width")
),
selectInput("ycol",
"Y:",
choices = c("Sepal.Length", "Sepal.Width")
)
),
mainPanel(plotOutput("plot"))
)
)
server <- function(input,output) {
output$plot <- renderPlot({
iris %>%
ggplot(aes(input$xcol, input$ycol)) +
geom_point()
})
}
shinyApp(ui, server)
期望的输出:
【问题讨论】: