Shiny 根据不同的日期范围,从导入的数据中选择不同的绘图

Shiny 根据不同的日期范围,从导入的数据中选择不同的绘图,shiny,date-range,Shiny,Date Range,我正在尝试制作一个闪亮的应用程序,首先在第一个选项卡中导入数据,然后根据第二个选项卡中导入的数据绘制一个ggplot。我得到以下错误: do not know how to convert 'input$date[1]' to class “Date” 库(闪亮) 图书馆(GG2) df您是否尝试过读取.csv(infle$datapath,colClasses=c(“date”=“date”))? 顺便说一下,在代码中,有一个额外的括号dfplot=as.Date(输入$Date[1])&。

我正在尝试制作一个闪亮的应用程序,首先在第一个选项卡中导入数据,然后根据第二个选项卡中导入的数据绘制一个
ggplot
。我得到以下错误:

do not know how to convert 'input$date[1]' to class “Date”
库(闪亮)
图书馆(GG2)

df您是否尝试过读取.csv(infle$datapath,colClasses=c(“date”=“date”))
? 顺便说一下,在代码中,有一个额外的括号
dfplot=as.Date(输入$Date[1])&
。希望能有帮助

library(shiny)
library(ggplot2)

df <- data.frame("date" = c("2020-01-01", "2020-01-01", "2020-01-02", "2020-01-02"), "id" = c("A", "A", "B", "B"), "number" = c(1, 3, 2, 5))

write.csv(df, "df.csv", row.names = F)


if (interactive()) {
  ui <- fluidPage(
    tabsetPanel(
      tabPanel("Import Data",
               fileInput("file", "Upload Your File:"),
               DT::dataTableOutput("data")
               ),

      tabPanel("Plot",
               uiOutput("daterange"),
               plotOutput("graph")
               )
)
)


  server <- function(input, output) {
    newdata <- reactive({
      req(input$file)

      inFile <- input$file
      read.csv(inFile$datapath)
    })

    output$daterange <- renderUI({
      dates <- as.Date(newdata()$date)
      dateRangeInput("daterange", "Choose Your Date",
                     start = min(dates), end = max(dates),
                     min = min(dates), max = max(dates))
    })

    output$graph <- renderPlot({
      dfplot <- subset(newdata(), date >= as.Date(input$date[1])) & date <= as.Date(input$date[2]))

      g <- ggplot(dfplot, aes(x = id, y = number)) +
        geom_boxplot() +
        theme_classic()
      print(g)
    })

    output$data <- DT::renderDataTable({
      req(input$file)
      inFile <- input$file
      if (is.null(inFile))
        return(NULL)
      read.csv(inFile$datapath)
    })
  }
  shinyApp(ui = ui, server = server)
}