[英]Downloading wordcloud2 output on shiny.io does not work
我正嘗試在Shiny.io上托管的閃亮應用程序上從wordcloud2下載輸出。
以前,我有一個問題與下載wordcloud2輸出上的瀏覽器,並成功地解決這里它下載wordcloud2上閃亮PNG / JPG格式輸出 。
為了比較和清晰起見,我展示了適用於傳單地圖的類似下載功能。 之所以我包括傳單地圖部分,是因為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輸出(任何格式)有任何見解,將不勝感激。
我終於從這篇文章中發現,我需要通過將以下代碼行添加到庫調用部分來安裝幻影依賴項
webshot::install_phantomjs()
webshot:::find_phantom()
在Shiny.io上發布我的應用程序時
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.