0

I have the shiny app below in which I want to download a plotly plot using downloadhandler(). But as you will see when I run the app in web browser and download the image the lower section of the histogram is missing. Why does this happen? Can this be fixed or be downloaded alternativelly? In case you wonder why I have used uiOutput() for download button and the movies dataset it is because this is how my original and more complex app works. Before you begin:

 library(webshot)
 install_phantomjs()


#uir.r
library(shiny)
library(plotly)
library(ggplot2movies) # movies is no longer contained within ggplot2 https://cran.r-project.org/web/packages/ggplot2movies/index.html

shinyUI(fluidPage(
  titlePanel("Movie Ratings!"),
  sidebarPanel(
    uiOutput("down")
  ),
  mainPanel(
    plotlyOutput("trendPlot")
  )
))
#server.r
library(shiny)
library(plotly)
library(ggplot2movies) # movies is no longer contained within ggplot2 https://cran.r-project.org/web/packages/ggplot2movies/index.html

shinyServer(function(input, output) {


  output$down<-renderUI({
    output$downloadData <- downloadHandler(
      filename = function(){

        paste0(paste0("pic"), ".png")
      },
      content = function(file) {
            export(reg(), file=file)
      }) 
    downloadButton("downloadData", "Download")
  })

  reg<-reactive({
    movies
    # Create axes titles as lists
    x <- list(
      title = "A",
      dtick = 5 
    )
    y <- list(
      title = "B"
    )
    # Create the plotly histogram

    plot_ly(alpha = 0.9) %>%
      add_histogram(x = as.factor(movies$rating)) %>%
      # Add titles in plot and axes
      layout(barmode = "overlay",title = "SAD",xaxis=x,yaxis=y)
  })
  output$trendPlot <- renderPlotly({
    reg()

  })
})

SPOLIED IMAGE enter image description here

ismirsehregal
  • 30,045
  • 5
  • 31
  • 78
firmo23
  • 7,490
  • 2
  • 38
  • 114
  • Weird. For an alternative way to download, see https://stackoverflow.com/questions/53314307/download-plotly-using-downloadhandler/53317200#53317200 – Stéphane Laurent Feb 13 '19 at 10:42
  • I have already tried to implement it here. https://stackoverflow.com/questions/54593775/error-in-plotly-graph-download-from-a-shiny-app-when-using-javascript But I would like to use a downloadhandler instead of an actionbutton which will be activated from uiOutput. Can you help? – firmo23 Feb 13 '19 at 14:15
  • I did that using javascript. Anyway I leave this Q because it is about a different issue. – firmo23 Feb 13 '19 at 14:57
  • Using [orca](https://plot.ly/r/static-image-export/) (as mentioned to you [here](https://stackoverflow.com/questions/54586780/download-a-dynamic-plotly-graph-using-dynamic-downloadhandler-from-a-shiny-app) already) is not an option? Running your code gives me a warning `Warning: 'export' is deprecated. Use 'orca' instead. See help("Deprecated")` – ismirsehregal Feb 15 '19 at 09:03

0 Answers0