1
我试图应用this question节省情节给出的答案和this question下载无功输出没有成功。我不确定我的反应函数是否输出了错误的数据类型,或者我的downloadHandler()
写入不正确。包含反应性对象在闪亮的出口
此外,链接的问题通过function()
s到reactive()
我被警告已被弃用,所以我在这里避免它。 (该行为并没有改变,虽然)。
ui.R:
library(shiny)
# Define UI for application
shinyUI(pageWithSidebar(
# Application title
headerPanel("App"),
sidebarPanel(
downloadButton("savemap", label="Download Map (Hires)")
),
mainPanel(
tabsetPanel(
tabPanel("Map",
plotOutput("myworld", height="650px",width="750px",
clickId="plotclick")
)
)
)
))
server.R
library(shiny)
library(maps)
library(mapdata)
library(rworldmap)
library(gridExtra)
shinyServer(function(input, output) {
theworld <- reactive({
myplot <- map("world2", wrap=TRUE, plot=TRUE,
resolution=2)
})
output$myworld <- renderPlot({
print(theworld())
})
output$savemap <- downloadHandler(
filename = function() {
paste('fuzzymap-', Sys.Date(), '.png', sep="")
},
content = function(file) {
# function to actually write the image file
# https://stackoverflow.com/questions/14810409/save-plots-made-in-a-shiny-app?rq=1
png(file)
print(theworld())
dev.off()
})
})
中的活性功能的地图在启动时成功地绘制。下载提示生成并且一个png文件下载,但它不包含任何数据。此外,将返回以下非致命错误,但搜索结果显示,没有线索:
Error opening file: 2
Error reading: 9
@haddley:我有在一个zip下载多个文件一些困难。你介意看看http://stackoverflow.com/questions/27067975/shiny-r-zip-multiple-pdfs-for-download/27068514#27068514 –