ropensci / iheatmapr

Complex, interactive heatmaps in R
https://docs.ropensci.org/iheatmapr
Other
267 stars 35 forks source link

downloading static iheatmapr works locally but not on shinyapps.io server #40

Closed Tomer-Tsaban closed 5 years ago

Tomer-Tsaban commented 5 years ago

Hi Alicia, and first much gratitude for your help and high responsiveness.

I noticed (what I think is) a bug, when downloading a static instance of iheatmapr - works for a local shiny app, but not on when uploaded to shinyapps.io server.

here's an example reproducible code for a simple app using measles data. also, here's a link to the same exact app on my shinyappsio user, where you could observe the download issue: url: https://tomertsaban.shinyapps.io/test_deploy_iheatmapr/

code: `library(shiny) library(iheatmapr) data(measles, package = "iheatmapr")

ui<-fluidPage( iheatmaprOutput("test"), downloadButton("download_test","download_heatmap") )

server<-function(session,input,output){

    heatmap_reactive<-reactive({
            test_heatmap<-main_heatmap(measles, name = "Measles<br>Cases", x_categorical = FALSE,
                         layout = list(font = list(size = 8))) %>%
                    add_col_groups(ifelse(1930:2001 < 1961,"No","Yes"),
                                   side = "bottom", name = "Vaccine<br>Introduced?",
                                   title = "Vaccine?",
                                   colors = c("lightgray","blue")) %>%
                    add_col_labels(ticktext = seq(1930,2000,10),font = list(size = 8)) %>%
                    add_row_labels(size = 0.3,font = list(size = 6)) %>% 
                    add_col_summary(layout = list(title = "Average<br>across<br>states"),
                                    yname = "summary")  %>%                 
                    add_col_title("Measles Cases from 1930 to 2001", side= "top") %>%
                    add_row_summary(groups = TRUE, 
                                    type = "bar",
                                    layout = list(title = "Average<br>per<br>year",
                                                  font = list(size = 8)))

    })

    output$test<-renderIheatmap(

            heatmap_reactive()

    )

    output$download_test<-downloadHandler(
            filename ="test_heatmap.png",
            content = function(file){
                    #cormap<-correlation_heatmap() 
                    #cormap <-cormap %>% add_col_title(input$plot_title,side="top")
                    save_iheatmap(heatmap_reactive(),file,vwidth=2000,vheight=1000)
            },
            contentType = "image/png"
    )

}

shinyApp(ui,server)`

I assumed you would like to know about this. Thanks again!

AliciaSchep commented 5 years ago

Very delayed, but I figured out the issue: The 'webshot' library is needed but the app doesn't know that (it is just a 'Suggests' of iheatmapr and not an imports b/c only needed if you want to save). Webshot also needs to install phantomjs. If you add a call to

library(webshot)
webshot::install_phantomjs()

in your app it will fix the issue... see https://aschep.shinyapps.io/test_app/

AliciaSchep commented 5 years ago

Am adding a note to the documentation of save_iheatmap about this use case.