0

我正在使用 R Shiny 制作应用程序。我将此命令放在程序的顶部:

options(shiny.maxRequestSize=-1)

显然,此命令允许用户上传任何大小的文件(默认为 5 MB 限制)。我也试过:

options(shiny.maxRequestSize=30*1024^2)

我认为这是 30 MB 的限制。

但是,每当我尝试上传大于 5 MB 的文件时,R 就会崩溃,并且在尝试加载文件大约一分钟后,我会收到“R 遇到致命错误”消息。

编辑:进一步的测试表明我输出的 gVis 表导致了崩溃。为什么会这样?

我的代码适用于 5 MB 以下的任何文件。

一些代码:

用户界面

dataset <- list('Upload a file'=c(1))

shinyUI(pageWithSidebar(

  sidebarPanel(

    fileInput('file', 'Data file'),
    radioButtons('format', 'Format', c('CSV', 'TSV')),



      conditionalPanel(condition = "input.tsp == 'sort'",
                       checkboxInput(inputId = "pageable", label = "Make table pageable"),
                       conditionalPanel("input.pageable==true",
                                        numericInput(inputId = "pagesize",
                                                     label = "Entries per page",10))              


      ),
      conditionalPanel(condition = "input.tsp == 'multi' ",


          selectInput('x', 'X', names(dataset)),
          selectInput('y', 'Y', names(dataset),  multiple=T),
          selectInput('color', 'Color', c('None', names(dataset))),

          checkboxInput('jitter', 'Jitter'),
          checkboxInput('smooth', 'Smooth'),

          selectInput('facet_row', 'Facet Row', c(None='.', names(dataset))),
          selectInput('facet_col', 'Facet Column', c(None='.', names(dataset)))

      )

  ),

  mainPanel( 
      tabsetPanel(
        tabPanel("Sortable Table", htmlOutput("gvisTable"),value="sort"),
        tabPanel("Multiplot", plotOutput('plotMulti'), value="multi"),
        id="tsp"            #id of tab
      )

  )
))

服务器.R

library(reshape2)
library(googleVis)
library(ggplot2)

options(shiny.maxRequestSize=-1)

shinyServer(function(input, output, session) {

  #-----------------------------------------------------------
  # Dataview Tab Inputs
  #-----------------------------------------------------------  

  data <- reactive({

    if (is.null(input$file))
      return(NULL)
    else if (identical(input$format, 'CSV'))
      return(read.csv(input$file$datapath))
    else
      return(read.delim(input$file$datapath))
  })

  observe({
    df <- data()
    str(names(df))
    if (!is.null(df)) {
      updateSelectInput(session, 'x', choices = names(df))
      updateSelectInput(session, 'y', choices = names(df))
      updateSelectInput(session, 'color', choices = c('None', names(df)))
      updateSelectInput(session, 'facet_row', choices = c(None='.', names(df)))
      updateSelectInput(session, 'facet_col', choices = c(None='.', names(df)))

    }
  })


  myOptions <- reactive({
    list(

      page=ifelse(input$pageable==TRUE,'enable','disable'),
      pageSize=input$pagesize,
      width=1000

      )
  })

  output$gvisTable <- renderGvis( {
    if (is.null(data()))
      return(NULL)

    gvisTable(data(), options=myOptions())


  })

  #-----------------------------------------------------------
  # Graphs
  #-----------------------------------------------------------  


  output$plotMulti <- renderPlot({
    if (is.null(data()))
      return(NULL)

    temp <- input$x
    p <- ggplot(data(), aes_string(x=temp, y=input$y), environment = environment()) 
    p <- p + geom_bar()

    if (input$smooth)
      p <- p + geom_smooth()

    if (input$color != 'None')
      p <- p + aes_string(color=input$color)

    facets <- paste(input$facet_row, '~', input$facet_col)
    if (facets != '. ~ .')
      p <- p + facet_grid(facets)

    if (input$jitter)
      p <- p + geom_jitter()


    multiplot(p, p)


  })


})
4

0 回答 0