【问题标题】:update x / y plot based on user input (Shiny)根据用户输入更新 x / y 图(闪亮)
【发布时间】: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)

期望的输出:

电流输出:

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    您正在尝试使用 aes 函数中的字符向量映射美学。你需要aes_string

    ###<Omitted Library Calls and UI> 
    
    server <- function(input,output) {
      output$plot <- renderPlot({
        iris %>%
          ggplot(aes_string(x= input$xcol, y = input$ycol)) +
          geom_point()
      })
    }
    
    ###<Omitted shinyApp call>
    

    【讨论】:

      猜你喜欢
      • 2018-04-30
      • 1970-01-01
      • 2016-12-09
      • 2020-06-23
      • 2020-12-29
      • 2021-04-18
      • 2014-06-19
      • 1970-01-01
      • 2021-11-03
      相关资源
      最近更新 更多