下面有一个闪亮的应用程序,我想在其中使用downloadhandler()
下载一个绘图。但是,正如您将看到的,当我在Web浏览器中运行该应用程序并下载图像时,直方图的下部丢失了。为什么会这样?可以修复此问题还是可以替代下载?如果您想知道为什么我对下载按钮和电影数据集使用了uiOutput()
,那是因为这就是我原来更复杂的应用程序的工作方式。开始之前:
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()
})
})