简体   繁体   中英

How to make a boxplot for Shiny web page

Good day

I am trying to make a simple boxplot for a shiny web page but for some reason, it is not working. I did it in markdown using the below code and I got the results I wanted.

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

This is what I get in markdown, which is also what I want for the shiny web page在此处输入图像描述

The following code is what I am using for the shiny web page

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)

As you can see the code I use to create the boxplots here is almost the same as what I used in markdown. So why do I get this when I run the app?

在此处输入图像描述

Any help in fixing this problem will be greatly appreciated!

I had to use the following code to fix my problem

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM