Case Studies: Building Web Applications with Shiny in R
Dean Attali
Shiny Consultant
Plots are common first step when exploring new dataset
plotOutput("my_plot")
output$my_plot <- renderPlot({
# code for a plot
})
Downloading is supported using download button
Comma Separated Values
Store small-medium datasets
CSV of gapminder:
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
Create CSV file:
write.csv(gapminder, "myfile.csv")
Download button is treated as output
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()
has two argumentsfilename
content(file)
Case Studies: Building Web Applications with Shiny in R