R 有光泽的绘图不显示数据

R 有光泽的绘图不显示数据,r,shiny,shinydashboard,R,Shiny,Shinydashboard,我正在尝试构建一个闪亮的应用程序,通过ECDC网站每日更新,显示10个受影响最严重国家的新冠病毒-19病例。我希望能够使用滑块输入限制病例和死亡,并使用日期输入选择日期周期(所有都已添加)。 代码如下,但当我运行应用程序时,我得到一个空白绘图,轴显示正确,但我无法获得要显示的点。这应该能够在任何计算机上运行,因为代码只是从ECDC页面下载数据集。 有什么解决办法吗 library(shiny) library(readxl) library(dplyr) library(httr) librar

我正在尝试构建一个闪亮的应用程序,通过ECDC网站每日更新,显示10个受影响最严重国家的新冠病毒-19病例。我希望能够使用滑块输入限制病例和死亡,并使用日期输入选择日期周期(所有都已添加)。 代码如下,但当我运行应用程序时,我得到一个空白绘图,轴显示正确,但我无法获得要显示的点。这应该能够在任何计算机上运行,因为代码只是从ECDC页面下载数据集。 有什么解决办法吗

library(shiny)
library(readxl)
library(dplyr)
library(httr)
library(ggplot2)
library(plotly)

url <- paste("https://www.ecdc.europa.eu/sites/default/files/documents/COVID-19-geographic-disbtribution-worldwide-",format(Sys.time(), "%Y-%m-%d"), ".xlsx", sep = "")

GET(url, authenticate(":", ":", type="ntlm"), write_disk(tf <- tempfile(fileext = ".xlsx")))

data <- read_excel(tf)

include<-c("United_Kingdom","Italy","France","China",
           "United_States_of_America","Spain","Germany",
           "Iran","South_Korea","Switzerland")
ui <- fluidPage(

    titlePanel("COVID-19 Daily Confirmed Cases & Deaths"),

    sidebarLayout(
        sidebarPanel(
            checkboxGroupInput("Country", "Select Country", selected = NULL, inline = FALSE,
                         width = NULL),
            dateRangeInput("DateRep","Select Date Range", start = "2019-12-31", end = NULL),
            sliderInput("Cases","Select Cases Range", min = 1, max = 20000, value = NULL),
            sliderInput("Deaths", "Select Death Range", min = 1, max = 10000, value = 100),
            submitButton("Refresh")


        ),

        mainPanel(
           plotOutput("plot")
        )
    )
)

server <- function(input, output) {

    output$plot <- renderPlot({

        include<-input$Country

        plot_data<-filter(data, `Countries and territories` %in% include)%>%
            filter(between(input$Cases))

        plot_data%>% ggplot(aes(x=input$DateRep, y=input$Cases, size =input$Deaths, color = input$Country)) +
            geom_point(alpha=0.5) +
            theme_light()

    })
}

shinyApp(ui = ui, server = server)
库(闪亮)
图书馆(readxl)
图书馆(dplyr)
图书馆(httr)
图书馆(GG2)
图书馆(绘本)

url我开始修复此问题,但时间不够了。。。这就是我所做的,也许你可以完成它

library(shiny)
library(readxl)
library(dplyr)
library(httr)
library(ggplot2)
library(plotly)

url <- paste("https://www.ecdc.europa.eu/sites/default/files/documents/COVID-19-geographic-disbtribution-worldwide-",format(Sys.time(), "%Y-%m-%d"), ".xlsx", sep = "")

GET(url, authenticate(":", ":", type="ntlm"), write_disk(tf <- tempfile(fileext = ".xlsx")))

data <- read_excel(tf)

ui <- fluidPage(

  titlePanel("COVID-19 Daily Confirmed Cases & Deaths"),

  sidebarLayout(
    sidebarPanel(
      uiOutput("country_checkbox"),
      dateRangeInput("DateRep","Select Date Range", start = "2019-12-31", end = NULL),
      sliderInput("Cases","Select Cases Range", min = 1, max = 20000, value = NULL),
      sliderInput("Deaths", "Select Death Range", min = 1, max = 10000, value = 100)
      #submitButton("Refresh")


    ),

    mainPanel(
      plotOutput("plot")
    )
  )
)

server <- function(input, output) {

  output$country_checkbox <- renderUI({
    countries <- unique(data.frame(data)[, "Countries.and.territories"])
    checkboxGroupInput("country", "Select Country", 
                       choices = countries,
                       selected = NULL, inline = FALSE,
                       width = NULL)
  })

  output$plot <- renderPlot({

    include<-input$country

    plot_data<-filter(data, `Countries and territories` %in% include)%>%
      filter(between(Cases, 1, input$Cases))

    plot_data%>% ggplot(aes(x=DateRep, y=Cases, size =Deaths, color = `Countries and territories`)) +
      geom_point(alpha=0.5) +
      theme_light()

  })
}

shinyApp(ui = ui, server = server)
库(闪亮)
图书馆(readxl)
图书馆(dplyr)
图书馆(httr)
图书馆(GG2)
图书馆(绘本)

url我开始修复此问题,但时间不够了。。。这就是我所做的,也许你可以完成它

library(shiny)
library(readxl)
library(dplyr)
library(httr)
library(ggplot2)
library(plotly)

url <- paste("https://www.ecdc.europa.eu/sites/default/files/documents/COVID-19-geographic-disbtribution-worldwide-",format(Sys.time(), "%Y-%m-%d"), ".xlsx", sep = "")

GET(url, authenticate(":", ":", type="ntlm"), write_disk(tf <- tempfile(fileext = ".xlsx")))

data <- read_excel(tf)

ui <- fluidPage(

  titlePanel("COVID-19 Daily Confirmed Cases & Deaths"),

  sidebarLayout(
    sidebarPanel(
      uiOutput("country_checkbox"),
      dateRangeInput("DateRep","Select Date Range", start = "2019-12-31", end = NULL),
      sliderInput("Cases","Select Cases Range", min = 1, max = 20000, value = NULL),
      sliderInput("Deaths", "Select Death Range", min = 1, max = 10000, value = 100)
      #submitButton("Refresh")


    ),

    mainPanel(
      plotOutput("plot")
    )
  )
)

server <- function(input, output) {

  output$country_checkbox <- renderUI({
    countries <- unique(data.frame(data)[, "Countries.and.territories"])
    checkboxGroupInput("country", "Select Country", 
                       choices = countries,
                       selected = NULL, inline = FALSE,
                       width = NULL)
  })

  output$plot <- renderPlot({

    include<-input$country

    plot_data<-filter(data, `Countries and territories` %in% include)%>%
      filter(between(Cases, 1, input$Cases))

    plot_data%>% ggplot(aes(x=DateRep, y=Cases, size =Deaths, color = `Countries and territories`)) +
      geom_point(alpha=0.5) +
      theme_light()

  })
}

shinyApp(ui = ui, server = server)
库(闪亮)
图书馆(readxl)
图书馆(dplyr)
图书馆(httr)
图书馆(GG2)
图书馆(绘本)

url我认为最好在
renderPlot
之外的
reactive
表达式中定义并过滤要绘制的数据。它将允许您更容易地重复使用这些数据,并且(从我的角度来看)更容易使用
ggplot
,而无需直接输入


我将
as.Date(DateRep)>=input$DateRep[1]&as.Date(DateRep)我认为最好在
renderPlot
之外的
反应式
表达式中定义和过滤要绘制的数据。它将允许您更容易地重复使用这些数据,并且(从我的角度来看)更容易使用
ggplot
,而无需直接输入


我包括
as.Date(DateRep)>=input$DateRep[1]&as.Date(DateRep)您可以添加
print(head(plot_data))
以查看是否向绘图功能获取任何数据吗?运行应用程序时,输出将在控制台中。这是在控制台中还是在脚本中?如果在控制台中打印数据,并且如果我将其添加到shinyApp(ui=ui,server=server)上方的脚本中,则也会正确打印数据,以便正确构建数据。我注意到,在您的绘图中,美学是数据中的输入,而不是字段。您可能需要
aes\u string
而不是
aes
来使用这样的输入。这没有起到令人遗憾的作用。看起来
input$DateRep
是两个日期的向量。你想把什么作为情节的美学?您给它两个字符串日期…您可以添加一个
打印(head(plot\u data))
来查看您是否正在向plotting函数获取任何数据吗?运行应用程序时,输出将在控制台中。这是在控制台中还是在脚本中?如果在控制台中打印数据,并且如果我将其添加到shinyApp(ui=ui,server=server)上方的脚本中,则也会正确打印数据,以便正确构建数据。我注意到,在您的绘图中,美学是数据中的输入,而不是字段。您可能需要
aes\u string
而不是
aes
来使用这样的输入。这没有起到令人遗憾的作用。看起来
input$DateRep
是两个日期的向量。你想把什么作为情节的美学?你给它两个字符串日期。。。