案例研究:使用 R 的 Shiny 建置網頁應用程式
Dean Attali
Shiny Consultant
探索新資料集時,繪圖常是第一步
plotOutput("my_plot")
output$my_plot <- renderPlot({
# code for a plot
})
下載功能可用下載按鈕完成

Comma Separated Values(逗號分隔值)
儲存小到中型資料集
gapminder 的 CSV:
country,continent,year,lifeExp,pop,gdpPercap
Afghanistan,Asia,1952,28.801,8425333,779.4453145
Afghanistan,Asia,1957,30.332,9240934,820.8530296
Afghanistan,Asia,1962,31.997,10267083,853.10071
Afghanistan,Asia,1967,34.02,11537966,836.1971382
建立 CSV 檔:
write.csv(gapminder, "myfile.csv")
下載按鈕視為輸出
downloadButton(outputId = "download_data",
label = "Download data")
output$download_data <- downloadHandler(
filename = "data.csv",
content = function(file) {
# Code that creates a file in the path <file>
write.csv(gapminder, file)
}
)
output$download_data <- downloadHandler(
filename = "data.csv",
content = function(file) {
# code that creates a file in the path <file>
write.csv(gapminder, file)
}
)
downloadHandler() 有兩個引數filenamecontent(file)案例研究:使用 R 的 Shiny 建置網頁應用程式