我正在尝试在Shiny.io上托管的闪亮应用程序上从wordcloud2下载输出。
以前,我在通过浏览器下载wordcloud2输出时遇到了问题,并设法在Downloading wordcloud2 output as png/jpg on shiny处解决了该问题。
为了比较和清楚起见,我展示了类似的下载功能,该功能适用于传单地图。之所以我包括传单地图部分,是因为wordcloud 2和传单地图输出都是html,因此我认为它们的行为相同。
下面的代码显示
library(leaflet)
library(htmlwidgets)
library(webshot)
library(shiny)
library(wordcloud2)
ui <- fluidPage(
leafletOutput("map"),
downloadLink("downloadMap", "Download1"),
downloadLink("savemap", "Download2"),
wordcloud2Output("wordclH2020"),
downloadLink( "savecloud", "DImage"),
downloadLink( "saveword", "DImage2")
)
server <- function(input,output) {
###### MAP SECTION ##############################
mapReact <- reactive({
leaflet() %>%
addTiles('http://{s}.tile.openstreetmap.de/tiles/osmde/{z}/{x}/{y}.png') %>%
addCircles(12.5,42,radius=500) %>% addMarkers(12,42,popup="Rome")
})
output$map <- renderLeaflet({
mapReact()
})
##### map download 1 works on browser but not shiny.io ###########
output$downloadMap <- downloadHandler(
filename = paste("LeafletMap", '.png', sep=''),
content = function(file) {
owd <- setwd(tempdir())
on.exit(setwd(owd))
saveWidget(mapReact(), "temp.html", selfcontained = FALSE)
webshot("temp.html", file = file, cliprect = "viewport")
})
##### map download 2 works on both browser and shiny.io ###########
output$savemap <- downloadHandler(
filename = "map.html",
content = function(file){
saveWidget(
widget = mapReact()
, file = file
)
}
)
############### WORD CLOUD SECTION ###############################
wordcl <- reactive ({
wordcloud2(demoFreq, color = "random-light", backgroundColor = "grey") })
output$wordclH2020 <- renderWordcloud2({ wordcl() })
##### wordcloud download 1 works on browser but not shiny.io ###########
output$savecloud <- downloadHandler(
filename = paste("LeafletMap", '.png', sep=''),
content = function(file) {
owd <- setwd(tempdir())
on.exit(setwd(owd))
saveWidget(wordcl(), "temp.html", selfcontained = FALSE)
webshot("temp.html", delay =15, file = file, cliprect = "viewport")
})
##### wordcoud download 2 does not work on browser nor shiny.io ###########
output$saveword <- downloadHandler(
filename = "word.html",
content = function(file){
saveWidget(
widget = wordcl()
, file = file
)
}
)
}
shinyApp(ui, server)
任何对如何从Shiny.io上托管的应用程序下载wordcloud2输出(任何格式)的见解都会受到赞赏。
答案 0 :(得分:0)
我最终从这个Retrieve Printer File Attributes (QDFRPRTA) API得出结论,我需要通过将以下代码行添加到库调用部分来安装幻影依赖项
webshot::install_phantomjs()
webshot:::find_phantom()
在Shiny.io上发布我的应用程序时