我在RStudio中创建了一个miniUI应用程序,它可以绘制用户可以导出某种格式(如pdf或png)的图表。不幸的是,当我使用Shiny Gadget时,导出功能似乎有问题。
是否有解决问题的已知解决方案?
这是一个小例子:
library(shiny)
library(miniUI)
ui <- miniPage(
gadgetTitleBar("Sample Gadget"),
miniContentPanel(
plotOutput("testPlot", height = "100%"),
downloadButton('downloadPlot', 'download button')
)
)
server <- function(input, output, session) {
plotInput <- function(){
plot(mtcars)
}
output$testPlot <- renderPlot({
print(plotInput())
})
output$downloadPlot <- downloadHandler(
filename = function() { paste("export", '.png', sep='') },
content = function(file) {
png(file,
bg="white",
type="cairo",
units="in",
width=10,
height=8,
pointsize=12,
res=180)
par(mar=c(0,0,0,0), xaxs = "i", yaxs = "i")
print(plotInput())
dev.off()
})
}
runGadget(shinyApp(ui, server))
我注意到当我在外部模式下运行应用程序时:
runGadget(shinyApp(ui, server), viewer = browserViewer())
它工作正常,但我更喜欢在对话模式下使用。
答案 0 :(得分:0)
最后我发现了这个问题:
Microsoft R Open(3.3.2)可能存在问题。当尝试从MRAN安装最新的闪亮包时它只安装'shiny_0.14.1.zip'
我用R 3.3.2尝试过,一切看起来都很好。
MRO 3.3.2:
Installing package into ‘C:/Users/tarkomatas/Documents/R/win-library/3.3’
(as ‘lib’ is unspecified)
trying URL 'https://mran.revolutionanalytics.com/snapshot/2016-11-01/bin/windows/contrib/3.3/shiny_0.14.1.zip'
Content type 'application/zip' length 2649191 bytes (2.5 MB)
downloaded 2.5 MB
R 3.3.2:
Installing package into ‘C:/Users/tarkomatas/Documents/R/win-library/3.3’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/shiny_1.0.0.zip'
Content type 'application/zip' length 2745865 bytes (2.6 MB)
downloaded 2.6 MB
奇怪的问题......