開始使用免費開始

進一步探索 Gapminder 資料

在 Shiny 應用中使用 gapminder 資料時,你常常需要篩選資料集,只保留部分列。你可以使用 subset() 函式來達成。

本練習屬於課程

案例研究:使用 R 的 Shiny 建置網頁應用程式

檢視課程

練習說明

已為你提供一個包含空白文字輸出的 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)
編輯並執行程式碼