用 Shiny 探索資料集

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

Dean Attali

Shiny Consultant

用 Shiny 探索資料集

Dataset

+ 互動環境

+ 檢視資料

+ 篩選資料

+ 下載資料

= Shiny 應用程式

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

以表格視覺化資料

country continent year lifeExp pop gdpPercap
Afghanistan Asia 1952 28.801 8425333 779.445315
Afghanistan Asia 1957 30.332 9240934 820.85303
Afghanistan Asia 1962 31.997 10267083 853.10071
Afghanistan Asia 1967 34.02 11537966 836.197138
Afghanistan Asia 1972 36.088 13079460 739.981106
Afghanistan Asia 1977 38.438 14880372 786.11336
Afghanistan Asia 1982 39.854 12881816 978.011439
Afghanistan Asia 1987 40.822 13867957 852.39595
Afghanistan Asia 1992 41.674 16317921 649.34140
Afghanistan Asia 1997 41.763 22227415 635.34135
案例研究:使用 R 的 Shiny 建置網頁應用程式

Shiny 中的表格

  • 表格是輸出

    • UI 中以輸出預留函式呈現:
    tableOutput("my_table")
    
    • 伺服器用 render 函式產生輸出:
    output$my_table <- renderTable({
        gapminder
    })
    
案例研究:使用 R 的 Shiny 建置網頁應用程式

篩選表格資料

  • 輸入可用來篩選

    • 在 UI 加入輸入元件:
    selectInput("country", "Country",
                choices = levels(gapminder$country))
    
    • 用輸入篩選資料:
  output$my_table <- renderTable({
      subset(gapminder, country == input$country)
  })
案例研究:使用 R 的 Shiny 建置網頁應用程式

選項設定:select input

  • selectInput()choices 參數可為任何字串清單

    • choices 可取變數的子集合
    selectInput("country", "Country",
                choices = levels(gapminder$country)[1:10])
    
    • choices 也可擴充加入新值
    selectInput("country", "Country",
                choices = c("any", levels(gapminder$country)))
    
案例研究:使用 R 的 Shiny 建置網頁應用程式

一起來練習吧!

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

Preparing Video For Download...