R闪亮文件输入大文件

Mic*_*ran 3 file-io r shiny

我对 R Shiny 有一些问题fileInput。默认大小限制设置为 5MB。\n由于我必须使用的文件非常大(> 50GB),因此我只需要数据路径和/或文件名。不幸的是,fileInput我想上传完整的文件,或者至少它以某种方式加载文件,并在我达到 5MB 限制后告诉我文件太大。

\n\n

如何只将路径移交给我的应用程序而不上传文件?

\n\n

ui.R

\n\n
library(shiny)\n\n# Define UI ----\nshinyUI(fluidPage(\nh1("SAS Toolbox"),\n\ntabsetPanel(\n  tabPanel("SASFat",\n     sidebarPanel(h2("Input:"),\n        actionButton("runSASFat","Run Job",width="100%",icon("paper-plane"), \n        style="color: #fff; background-color: #337ab7; border-color: #2e6da4"),       \n\n        wellPanel(\n           #tags$style(".shiny-file-input-progress {display: none}"),\n           fileInput("FEInp","Pfad FE input Deck:"), \n           fileInput("FERes","Pfad FE Results:") \n        ),\n        wellPanel(\n           checkboxGroupInput("options1","Auswertung:",c("Grundmaterial","Schweissn\xc3\xa4hte")),\n           conditionalPanel(condition="$.inArray(\'Schweissn\xc3\xa4hte\',input.options1) > -1", \n           sliderInput("filter", "Filter:", 0.75, min = 0, max = 1))\n        ),\n        wellPanel(\n           radioButtons("solver", "Solver:", c("Ansys","Abaqus", "Optistruct")),\n           conditionalPanel(condition="input.solver == \'Ansys\'",selectInput("lic", "Lizenz",c("preppost","stba","meba"))) \n        ),\n        wellPanel(\n           checkboxGroupInput("options2","Optionen:",c("Schreibe LCFiles"))\n        )\n     ),\n     mainPanel(br(),h2("Output:"),width="30%")\n  ), \n  tabPanel("Nietauswertung"),\n  tabPanel("Spannungskonzept EN12663")\n  )\n))\n
Run Code Online (Sandbox Code Playgroud)\n\n

服务器R

\n\n
# Define server logic ----\nshinyServer(function(input, output) {\n  observeEvent(input$runSASFat, {\n    FEInp <- input$FEInp\n    FERes <- input$FERes\n    opt1 <- input$options1 \n    opt2 <- input$options2\n    filter <- input$filter\n    solver <- input$solver\n    lic <- input$lic\n\n    write(c(FEInp$datapath,FERes$datapath,opt1,opt2,filter,solver,lic),"ghhh.inp")\n    })\n})\n
Run Code Online (Sandbox Code Playgroud)\n\n

提前致谢

\n\n

迈克尔

\n

ism*_*gal 5

感谢@MichaelBird 提供的例子。我调整了您的代码,让用户无需选择文件即可取消请求(取消后您的应用程序崩溃了):

顺便说一下,这仅适用于托管闪亮应用程序的电脑。

library(shiny)

ui <- fluidPage(
  titlePanel("Choosing a file example"),
  sidebarLayout(
    sidebarPanel(
      actionButton("filechoose",label = "Pick a file")
    ),
    mainPanel(
      textOutput("filechosen")
    )
  )
)

server <- function(input, output) {

  path <- reactiveVal(value = NULL)

  observeEvent(input$filechoose, {

    tryPath <- tryCatch(
      file.choose()
      , error = function(e){e}
    )

  if(inherits(tryPath, "error")){
    path(NULL)
  } else {
    path(tryPath)
  }

  })

  output$filechosen <- renderText({
    if(is.null(path())){
      "Nothing selected"
    } else {
      path()
    }
  })

}

shinyApp(ui = ui, server = server)
Run Code Online (Sandbox Code Playgroud)

另一种方法是增加上传的最大文件大小:

默认情况下,Shiny 将文件上传限制为每个文件 5MB。您可以使用shiny.maxRequestSize选项修改此限制。例如,将 options(shiny.maxRequestSize = 30*1024^2) 添加到 app.R 的顶部会将限制增加到 30MB。

请参阅这篇 RStudio文章