【发布时间】:2020-12-07 18:07:55
【问题描述】:
这是我第一次使用 Shiny,每次运行代码时都会遇到错误消息。
server <- function(input, output,
session){
#plot data
data <- reactive(
req(input$sel_location),
Covid_data <- Covid_data %>%
filter(location %in% input$sel_location)
)
#plot
output$plot <- renderPlot({
Covid_plot <- ggplot(data(), aes(
x= date, y = new_cases
)) + geom_bar()
})
}
ui <- basicPage(
h1("Covid data across the world"),
selectInput(inputId = "sel_location",
label = "Choose country",
list("India", "Pakistan")),
plotOutput("plot")
)
shinyApp(ui = ui, server = server)
我还想知道如何制作所有国家/地区的列表,而不仅仅是选定的国家/地区。
我收到的错误信息:
警告:错误:filter() 输入 ..1 有问题。
x 如果没有活动的反应上下文,则不允许操作。 (你试图做一些只能从反应式表达式或观察者内部完成的事情。)
ℹ 输入..1 是location %in% input$sel_location。
83:
错误:filter() 输入 ..1 有问题。
x 如果没有活动的反应上下文,则不允许操作。 (你试图做一些只能从反应式表达式或观察者内部完成的事情。)
ℹ 输入..1 是location %in% input$sel_location。
我正在使用的数据:
iso_code continent location date total_cases new_cases new_cases_smoothed total_deaths
1 AFG Asia Afghanistan 2020-01-23 NA 0 NA NA
2 AFG Asia Afghanistan 2020-01-24 NA 0 NA NA
3 AFG Asia Afghanistan 2020-01-25 NA 0 NA NA
4 AFG Asia Afghanistan 2020-01-26 NA 0 NA NA
5 AFG Asia Afghanistan 2020-01-27 NA 0 NA NA
6 AFG Asia Afghanistan 2020-01-28 NA 0 0 NA
new_deaths new_deaths_smoothed total_cases_per_million new_cases_per_million
1 0 NA NA 0
2 0 NA NA 0
3 0 NA NA 0
4 0 NA NA 0
5 0 NA NA 0
6 0 0 NA 0
new_cases_smoothed_per_million total_deaths_per_million new_deaths_per_million
1 NA NA 0
2 NA NA 0
3 NA NA 0
4 NA NA 0
5 NA NA 0
6 0 NA 0
new_deaths_smoothed_per_million reproduction_rate icu_patients icu_patients_per_million hosp_patients
1 NA NA NA NA NA
2 NA NA NA NA NA
3 NA NA NA NA NA
4 NA NA NA NA NA
5 NA NA NA NA NA
6 0 NA NA NA NA
hosp_patients_per_million weekly_icu_admissions weekly_icu_admissions_per_million weekly_hosp_admissions
1 NA NA NA NA
2 NA NA NA NA
3 NA NA NA NA
4 NA NA NA NA
5 NA NA NA NA
6 NA NA NA NA
weekly_hosp_admissions_per_million total_tests new_tests total_tests_per_thousand new_tests_per_thousand
1 NA NA NA NA NA
2 NA NA NA NA NA
3 NA NA NA NA NA
4 NA NA NA NA NA
5 NA NA NA NA NA
6 NA NA NA NA NA
new_tests_smoothed new_tests_smoothed_per_thousand positive_rate tests_per_case tests_units
1 NA NA NA NA
2 NA NA NA NA
3 NA NA NA NA
4 NA NA NA NA
5 NA NA NA NA
6 NA NA NA NA
stringency_index population population_density median_age aged_65_older aged_70_older gdp_per_capita
1 0 38928341 54.422 18.6 2.581 1.337 1803.987
2 0 38928341 54.422 18.6 2.581 1.337 1803.987
3 0 38928341 54.422 18.6 2.581 1.337 1803.987
4 0 38928341 54.422 18.6 2.581 1.337 1803.987
5 0 38928341 54.422 18.6 2.581 1.337 1803.987
6 0 38928341 54.422 18.6 2.581 1.337 1803.987
extreme_poverty cardiovasc_death_rate diabetes_prevalence female_smokers male_smokers
1 NA 597.029 9.59 NA NA
2 NA 597.029 9.59 NA NA
3 NA 597.029 9.59 NA NA
4 NA 597.029 9.59 NA NA
5 NA 597.029 9.59 NA NA
6 NA 597.029 9.59 NA NA
handwashing_facilities hospital_beds_per_thousand life_expectancy human_development_index
1 37.746 0.5 64.83 0.498
2 37.746 0.5 64.83 0.498
3 37.746 0.5 64.83 0.498
4 37.746 0.5 64.83 0.498
5 37.746 0.5 64.83 0.498
6 37.746 0.5 64.83 0.498
【问题讨论】: