如何为闪亮的网页制作箱形图

时间:2020-04-14 16:16:35

标签: r ggplot2 shiny boxplot shinyapps

美好的一天

我正在尝试为闪亮的网页制作一个简单的箱线图,但是由于某种原因,它无法正常工作。 我使用下面的代码在markdown中做到了,得到了想要的结果。

ggplot(test, aes(x = Date, y = test$Var1, group = Date)) +
  geom_boxplot()

这就是我在markdown中获得的东西,这也是我想要的闪亮网页 enter image description here

以下代码是我用于闪亮网页的代码

library(readxl)
library(shiny)
library(ggplot2)
library(dplyr)


ui <- fluidPage(
  titlePanel("questionnaire"),
  sidebarLayout(
    sidebarPanel(
      selectInput("question", "Choose a question",
                  colnames(test))
    ),
    mainPanel(
      plotOutput("coolplot")
    )
  )
)

server <- function(input, output) {
  output$coolplot <- renderPlot(
    ggplot(test, aes(x = Date, y = input$question, group = Date)) +
      geom_boxplot()
  )
  
}

shinyApp(ui = ui, server = server)

如您所见,我在这里用于创建箱形图的代码与我在markdown中使用的代码几乎相同。 那为什么在我运行该应用程序时会得到这个?

enter image description here

在解决此问题方面的任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

我必须使用以下代码来解决问题

server <- function(input, output) {
  output$coolplot <- renderPlot(
    ggplot(test, aes(x = Date, y = get(input$question), group = Date)) +
      geom_boxplot()
  )