进一步探索 Gapminder 数据
在 Shiny 应用中使用 gapminder 数据时,通常需要先筛选数据集,只保留部分行。您可以使用 subset() 函数来完成。
本练习是课程的一部分
案例研究:使用 R 的 Shiny 构建 Web 应用
练习说明
系统已为您提供了一个包含空文本输出的 Shiny 应用。您的任务是:
- 加载
gapminder包。 - 使用
subset()函数获取法国在 1972 年的人口,并在文本输出中显示该数值(第 14 行)。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Load the gapminder package
___
# Define UI for the application
ui <- fluidPage(
"The population of France in 1972 was",
textOutput("answer")
)
# Define the server function
server <- function(input, output) {
output$answer <- renderText({
# Determine the population of France in year 1972
subset(___ & ___)$___
})
}
# Run the application
shinyApp(ui = ui, server = server)