R for
Authoring!!

PSP Session #26…
…more Shiny buttons

Problem-Solving Panel
(May 21, 2024)

  • Recap session #25       ↔︎️
  • Focal issue:
    • Dashboard reports 📔
    • Shiny✨ downloads
  • Shared problem-solving

Recap of Session #25:

Shiny dashboard downloads


Working with Old Faithful Shiny template:

sliderInput("bins", "Number of bins:",           
            min = 1, max = 50, value = 30)

downloadLink('downloadData', 'Download')

plotOutput("distPlot")

## https://stackoverflow.com/questions/74947736/
## how-to-download-quarto-pdf-reports-from-r-
## shiny-application
1
downloadLink was appearing but downloadButton was not last week - ran out of time before could fully explore

All elements within this chunk are executed when the document is rendered

output$distPlot <- renderPlot({
   x <- faithful[, 2]  # Old Faithful Geyser data
   bins <- seq(min(x), max(x), 
               length.out = input$bins + 1)
   hist(x, breaks = bins, 
        col = 'darkgray', border = 'white',
        xlab = 'Waiting time to next eruption (in mins)',
        main = 'Histogram of waiting times')
})

output$downloadData <- downloadHandler(
   filename = function() {
     paste('data-', Sys.Date(), '.csv', sep='')
   },
   content = function(con) {
     write.csv(data, con)
   }
 )
1
Ran out of time last week, but downloadHandler seemed like a promising Plan A

Today:

Reporting from Shiny:

Session Info (May 21, 2024) Rendering:

R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8 
[2] LC_CTYPE=English_United States.utf8   
[3] LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.utf8    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] fontawesome_0.5.2

loaded via a namespace (and not attached):
 [1] lubridate_1.9.3   emo_0.0.0.9000    digest_0.6.31     crayon_1.5.2     
 [5] assertthat_0.2.1  lifecycle_1.0.4   jsonlite_1.8.8    magrittr_2.0.3   
 [9] evaluate_0.23     stringi_1.7.12    rlang_1.1.3       cli_3.6.0        
[13] rstudioapi_0.15.0 vctrs_0.6.5       generics_0.1.3    rmarkdown_2.26   
[17] tools_4.2.2       stringr_1.5.1     glue_1.6.2        purrr_1.0.1      
[21] xfun_0.42         yaml_2.3.8        fastmap_1.1.1     compiler_4.2.2   
[25] timechange_0.3.0  htmltools_0.5.7   knitr_1.45