Salvando mapas de folhetos em R brilhante
Eu criei um aplicativo em que o usuário pode modificar um mapa de folheto e gostaria de usá-lo em um relatório em pdf. Eu tenho 1. Folheto de pacotes instalados, Webshot e htmlwidget 2. Instalei o PhantomJS
abaixo está uma versão simplificada do código
server.R:
library(shiny)
library(leaflet)
library(htmlwidgets)
library(webshot)
shinyServer(function(input, output, session) {
output$amap <- renderLeaflet({
leaflet() %>%
addProviderTiles("Stamen.Toner",
options = providerTileOptions(noWrap = TRUE, reuseTiles=TRUE))
})
observe({
leafletProxy("amap") %>%
clearShapes() %>%
addCircles(lng = c(22,-2), lat = c(42,65))
})
observeEvent(input$saveButton,{
themap<- leafletProxy("amap")
saveWidget(themap, file="temp.html", selfcontained = F)
webshot("temp.html", file = "Rplot.png",
cliprect = "viewport")
})
})
ui.R:
fluidPage(
leafletOutput("amap", height="600px", width="600px"),
br(),
actionButton("saveButton", "Save")
)
Recebo esta mensagem de erro:
Aviso: Erro no system.file: 'package' deve ter o comprimento 1 Rastreio de pilha (primeiro mais interno): 73: system.file 72: readLines 71: paste 70: yaml.load 69: yaml :: yaml.load_file 68: getDependency 67: widget_dependencies 66: htmltools :: attachDependencies 65: toHTML 64: saveWidget 63: observeEventHandler [arquivos C: \ R \ test / server.R # 24] 1: shiny :: runApp
quando o botão salvar estiver ativado. O savewidget funciona bem quando eu defino o botão Salvar assim:
observeEvent(input$saveButton,{
themap<-leaflet() %>%
addProviderTiles("Stamen.Toner",
options = providerTileOptions(noWrap = TRUE, reuseTiles=TRUE))
saveWidget(themap, file="temp.html", selfcontained = F)
webshot("temp.html", file = "Rplot.png",
cliprect = "viewport")
})
Mas eu realmente quero as alterações que o usuário faz no webshot. Alguém pode ajudar?