我有下面的 shiny
应用程序,我想知道如何使用 downloadablePlot
Shiny 模块下载绘图。当我启动应用程序时,我得到 Error in visibleplot: could not find function "visibleplot"
。它应该是通过 shiny
包加载的,按钮没有显示。
library(shiny)
library(periscope)
ui <- fluidPage(
plotOutput("plot"),
downloadablePlotUI("object_id1",
downloadtypes = c("png", "csv"),
download_hovertext = "Download the plot and data here!",
height = "500px",
btn_halign = "left")
)
server <- function(input, output) {
output$plot<-renderPlot(plot(iris))
plotInput = function() {
plot(iris)
}
callModule(downloadablePlot,
"object_id1",
logger = ss_userAction.Log,
filenameroot = "mydownload1",
aspectratio = 1.33,
downloadfxns = list(png = plotInput),
visibleplot = plotInput)
}
shinyApp(ui = ui, server = server)
答案 0 :(得分:1)
downloadablePlotUI
上的文档说明如下:
此模块与内置(基础)图形(图形包提供的任何功能,如绘图)不兼容,因为它们无法保存到对象中,并且在创建时由系统直接输出。
您正在使用无法显示的 plot(iris)。
使用 ggplot
将显示绘图。我仍然没有收到下载按钮。
server <- function(input, output, session) {
output$plot<-renderPlot(plotInput())
plotInput <- function() {
ggplot(cars, aes(x=speed, y=dist))+geom_point()
}
plot <- ggplot(cars, aes(x=speed, y=dist))+geom_point()
callModule(downloadablePlot,
"object_id1",
logger = ss_userAction.Log,
filenameroot = "mydownload1",
aspectratio = 1.33,
downloadfxns = list(png = plotInput),
visibleplot = plotInput )
}