Я новичок в Shiny и столкнулся с проблемами при рендеринге ggplot. Я хочу отобразить график с несколькими строками, но получаю сообщение об ошибке: Предупреждение: ошибка в: Эстетика должна быть либо длиной 1, либо такой же, как data (1)
Он отлично работает, когда я визуализирую одну строку , но не множественные. Ранее были вопросы о переполнении стека, посвященные аналогичным проблемам, но, боюсь, я не полностью понимаю их суть.
Помощь будет очень признательна. :)
library(tidyverse)
library(shiny)
url <- paste("https://www.ecdc.europa.eu/sites/default/files/documents/COVID-19-geographic-disbtribution-worldwide-",format(Sys.time(), "%Y-%m-18"), ".xlsx", sep = "")
GET(url, authenticate(":", ":", type="ntlm"), write_disk(tf <- tempfile(fileext = ".xlsx")))
df <- read_excel(tf)
df <- df %>%
rename(country = countriesAndTerritories) %>%
arrange(country, dateRep) %>%
group_by(country) %>%
mutate(Cumulative_Death = cumsum(deaths)) %>%
ungroup() %>%
filter(Cumulative_Death > 9) %>%
group_by(country) %>%
mutate(numbers_of_days = row_number(),
First_Death_Date = min(dateRep)) %>%
select(country, numbers_of_days, deaths, Cumulative_Death)
ui <- fluidPage(
titlePanel("Statistik Covid-19"),
sidebarLayout(
sidebarPanel(
selectInput("cou", "Country:", choices = unique(df$country), selected = "SWeden", multiple = TRUE),
selectInput("var", "Variable:", choices = c("deaths", "Cumulative_Death"))),
mainPanel(
plotOutput("covid"))
))
server <- function(input, output, session){
selected <- reactive(filter(df, country %in% input$cou))
output$covid <- renderPlot({
ggplot(selected(), aes(x=numbers_of_days, input$var, colour = input$cou)) +
geom_line(size = 1.5) +
labs(title = "Covid-19: Antal döda per 100 000 invånare",
x = "DAGAR SEDAN ANTAL DÖDSFALL ÖVERSTEG TIO",
y = paste0(input$var),
caption = "Source: European Centre for Disease Prevention and Control") +
guides(colour = guide_legend(title=NULL))
})
}
shinyApp(ui, server)