Skip to content

Commit

Permalink
Should fix downloads (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
yvanrichard committed Apr 12, 2023
1 parent 75b3d8a commit fd93a32
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
33 changes: 23 additions & 10 deletions app/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -903,10 +903,8 @@ shinyServer(function(input, output, session) {
}
})


output$scoresPlot <- renderPlot({
debuginfo('Rendering scoresPlot')

plotdata <- reactive({
if (is.null(input$aggregate_site_visits)) return(NULL)

ibi_scores_both <- ibiData()
Expand Down Expand Up @@ -971,23 +969,38 @@ shinyServer(function(input, output, session) {
theme(axis.title.x = element_text(size = 12, margin = margin(t = 20)))+
theme(axis.title.y = element_text(size = 12, margin = margin(r = 14)))

g
})

output$scoresPlot <- renderPlot({
debuginfo('Rendering scoresPlot')

g <- plotdata()
rv$scoredistplot <- g
g
})

observe({
if (!is.null(input$view_region_only) && input$view_region_only != FALSE) {
fn <- sprintf('IBI-category-distribution_%s-region.png', gsub('\'', '', gsub(' ', '-', input$region)))
} else {
fn <- 'IBI-category-distribution_national.png'
}
debuginfo(fn)
rv$plotfilename <- fn
})

output$plotdl <- downloadHandler(
## filename = rv$plot_filename,
filename = function() {
## 'test.png'
if (!is.null(input$view_region_only) && input$view_region_only != FALSE) {
fn <- sprintf('IBI-category-distribution_%s-region.png', gsub('\'', '', gsub(' ', '-', input$region)))
sprintf('IBI-category-distribution_%s-region.png', gsub('\'', '', gsub(' ', '-', input$region)))
} else {
fn <- 'IBI-category-distribution_national.png'
'IBI-category-distribution_national.png'
}
fn
},
content = function(file) {
req(rv$scoredistplot)
ggsave(file, plot = rv$scoredistplot, device = "png", width = 7.5, height = 5)
ggsave(filename = file, plot = plotdata(), device = 'png', width = 7.5, height = 5, units = "in")
}
)

Expand Down Expand Up @@ -1185,7 +1198,7 @@ shinyServer(function(input, output, session) {

output$mapdl <- downloadHandler(
filename = function() {
if (!is.null(input$nview_region_only) && input$view_region_only != FALSE) {
if (!is.null(input$view_region_only) && input$view_region_only != FALSE) {
fn <- sprintf('IBI-category-map_%s-region.png', gsub('\'', '', gsub(' ', '-', input$region)))
} else {
fn <- 'IBI-category-map_national.png'
Expand Down
4 changes: 2 additions & 2 deletions app/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ fileInputOnlyButton <- function(..., label="") {

mydownloadbutton <- function(outputId, label = "Download", class = NULL, ...,
icon = shiny::icon("arrow-down")) {
aTag <- tags$a(id = outputId, class = paste("my-dl-btn", class),
href = "", target = "_blank", download = NA, span(label), shiny:::validateIcon(icon), ...)
aTag <- tags$a(id = outputId, class = paste("my-dl-btn shiny-download-link", class),
href = "", target = "_blank", download = NA, shiny:::validateIcon(icon), span(label), ...)
}

withspinner <- function(...) withSpinner(..., type = 5, color="#003547")
Expand Down
Loading

0 comments on commit fd93a32

Please sign in to comment.