Я написал следующие коды для создания COVID-19 Tracker с использованием пакета R Shiny, который показывает линейные графики случаев и смертей на уровне штата и округа. Но графики не появились. Вместо этого я вижу сообщение об ошибке, в котором говорится, что «non-Numberri c аргумент для двоичного оператора». Любая помощь будет оценена. Спасибо.
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
selectInput(inputId = "state_name",
label = "Select State",
choices = unique(combined$province_state),
selected = "Pennsylvania",
multiple = TRUE),
selectInput(inputId = "scale_type",
label = "Select Scale",
choices = c("Logarithmic" = "log", "Linear" = "linear"),
selected = "Logarithmic"),
selectInput(inputId = "data_type",
label = "Select Data",
choices = c("Total Confirmed Cases" = "total_cases",
"New Cases" = "new_cases",
"Total Deaths" = "total_deaths",
"New Deaths" = "new_deaths"),
selected = "Total Confirmed Cases"),
selectInput(inputId = "normalization_option",
label = "Select Normalization Option",
choices = c("Not Normalized" = FALSE,
"Normalized by Population" = TRUE),
selected = "Not Normalized")),
mainPanel(
plotlyOutput("state_graph"),
plotlyOutput("county_graph")
)
)
)
server <- function(input, output, session) {
reval <- reactive({
if_else(input$normalization_option == TRUE,
input$data_type/population*1000000,
input$data_type)
})
output$state_graph <- renderPlotly({
by_state <- combined %>%
group_by(province_state, date) %>%
summarise(population = sum(population),
total_cases = sum(total_cases),
total_deaths = sum(total_deaths)) %>%
mutate(new_cases = total_cases-lag(total_cases, order_by = date),
new_deaths = total_deaths-lag(total_deaths, order_by = date)) %>%
mutate(over_20 = case_when(
total_cases >= 20 ~ 1,
TRUE ~ 0)) %>%
filter(over_20 == 1) %>%
mutate(days_since_20 = cumsum(over_20)) %>%
plot_ly(x = ~days_since_20, y = ~reval(),
color = ~province_state, type = "scatter", mode = "lines")
})
output$county_graph <- renderPlotly({combined %>%
filter(province_state == input$state_name) %>%
group_by(admin2, date) %>%
mutate(new_cases = total_cases-lag(total_cases, order_by = date),
new_deaths = total_deaths-lag(total_deaths, order_by = date)) %>%
mutate(over_5 = case_when(
total_cases >= 5 ~ 1,
TRUE ~ 0)) %>%
filter(over_5 == 1) %>%
mutate(days_since_5 = cumsum(over_5)) %>%
plot_ly(x = ~days_since_5, y = ~reval(),
color = ~province_state, type = "scatter", mode = "lines")
})
}