0

我有shiny下面的应用程序,我想知道如何使用downloadablePlotShiny Module 下载绘图。当我启动应用程序时,我得到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)
4

1 回答 1

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 )
  
}
于 2021-04-13T02:28:35.970 回答