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()
})
})