以表格檢視資料
探索資料集的第一步,通常就是把它以表格方式檢視。
到目前為止,我們主要著重在輸入——也就是讓使用者選擇數值的互動元件。現在我們想在應用程式中放入一個表格,並把資料送到表格中顯示。要在 Shiny 中顯示物件,需要搭配使用 output 與 render 系列函式。
本練習屬於課程
案例研究:使用 R 的 Shiny 建置網頁應用程式
練習說明
在一個最小化的 Shiny 應用程式中,加入能顯示 gapminder 資料集的表格。具體來說:
- 在 UI 建立一個 ID 為「table」的表格輸出,作為表格的佔位元。
- 在 server 程式碼中使用對應的 render 函式來繪製該表格。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
ui <- fluidPage(
h1("Gapminder"),
# Add a placeholder for a table output
___
)
server <- function(input, output) {
# Call the appropriate render function
output$table <- ___({
# Show the gapminder object in the table
gapminder
})
}
shinyApp(ui, server)