小编sba*_*sba的帖子

从Shiny(R)下载png

我对Shiny(和R)很陌生,并且正在努力将我在Shiny制作的情节导出为png文件.

我看了这两个线程,但无法弄清楚:

保存在闪亮的应用程序中制作的图片 Shiny downloadHandler不保存PNG文件

我设法在ui中创建下载按钮,服务器似乎也在做我想做的一切.当我点击预览窗口中的下载按钮时,弹出窗口会要求我指定文件位置和名称,但不保存任何文件.当我在浏览器窗口中执行相同操作时,会创建一个png文件但它是空的.

任何见解都非常感谢!

ui.R

library(shiny)

shinyUI(fluidPage(
  titlePanel("This is a scatterplot"),

  sidebarLayout(
    sidebarPanel(

      fileInput('datafile', 'Choose CSV file',
                accept=c('text/csv', 'text/comma-separated-values,text/plain')),

      uiOutput("varselect1"),

      uiOutput("varselect2"),

      downloadButton('downloadPlot', 'Download Plot')

      ),

    mainPanel(          
          h4("Here is your scatterplot"),
          plotOutput("plot1")
                  )
      ))
)
Run Code Online (Sandbox Code Playgroud)

server.R

library(foreign)

shinyServer(function(session,input, output) {

    DataInput <- reactive({
      infile <- input$datafile
      if (is.null(infile)) {

        return(NULL)
      }
      read.csv(infile$datapath)
    })


    output$varselect1 <- renderUI({

      if (identical(DataInput(), '') || identical(DataInput(),data.frame())) return(NULL)

      cols <- names(DataInput())
      selectInput("var1", "Select a variable:",choices=c("---",cols[3:length(cols)]), selected=("---"))

    })

    output$varselect2 <- renderUI({

      if (identical(DataInput(), '') || …
Run Code Online (Sandbox Code Playgroud)

png r download shiny

14
推荐指数
1
解决办法
9630
查看次数

标签 统计

download ×1

png ×1

r ×1

shiny ×1