首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >闪闪发光的fileInput大文件

闪闪发光的fileInput大文件
EN

Stack Overflow用户
提问于 2018-07-05 12:46:45
回答 2查看 3.2K关注 0票数 2

我对fileInput的R发亮有一些问题。大小限制设置为每个默认值5MB。因为我必须处理的文件非常大(>50 of ),所以我只需要数据路径和文件的名称。不幸的是,fileInput希望上传完整的文件,或者至少它正在以某种方式加载文件,并且告诉我,在我达到5MB的限制后,文件太大了。

我怎么能在不上传文件的情况下只提交到我的应用程序的路径?

ui.R

代码语言:javascript
复制
library(shiny)

# Define UI ----
shinyUI(fluidPage(
h1("SAS Toolbox"),

tabsetPanel(
  tabPanel("SASFat",
     sidebarPanel(h2("Input:"),
        actionButton("runSASFat","Run Job",width="100%",icon("paper-plane"), 
        style="color: #fff; background-color: #337ab7; border-color: #2e6da4"),       

        wellPanel(
           #tags$style(".shiny-file-input-progress {display: none}"),
           fileInput("FEInp","Pfad FE input Deck:"), 
           fileInput("FERes","Pfad FE Results:") 
        ),
        wellPanel(
           checkboxGroupInput("options1","Auswertung:",c("Grundmaterial","Schweissnähte")),
           conditionalPanel(condition="$.inArray('Schweissnähte',input.options1) > -1", 
           sliderInput("filter", "Filter:", 0.75, min = 0, max = 1))
        ),
        wellPanel(
           radioButtons("solver", "Solver:", c("Ansys","Abaqus", "Optistruct")),
           conditionalPanel(condition="input.solver == 'Ansys'",selectInput("lic", "Lizenz",c("preppost","stba","meba"))) 
        ),
        wellPanel(
           checkboxGroupInput("options2","Optionen:",c("Schreibe LCFiles"))
        )
     ),
     mainPanel(br(),h2("Output:"),width="30%")
  ), 
  tabPanel("Nietauswertung"),
  tabPanel("Spannungskonzept EN12663")
  )
))

server.R

代码语言:javascript
复制
# Define server logic ----
shinyServer(function(input, output) {
  observeEvent(input$runSASFat, {
    FEInp <- input$FEInp
    FERes <- input$FERes
    opt1 <- input$options1 
    opt2 <- input$options2
    filter <- input$filter
    solver <- input$solver
    lic <- input$lic

    write(c(FEInp$datapath,FERes$datapath,opt1,opt2,filter,solver,lic),"ghhh.inp")
    })
})

提前感谢

迈克尔

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-07-05 13:01:10

下面是一个示例,说明如何在一个闪亮的应用程序中使用file.choose()来获取文件的本地路径(以及文件名):

代码语言:javascript
复制
library(shiny)


ui <- fluidPage(

   # Application title
   titlePanel("Choosing a file example"),


   sidebarLayout(
      sidebarPanel(
        actionButton("filechoose",label = "Pick a file")
      ),

      mainPanel(
         textOutput("filechosen")
      )
   )
)


server <- function(input, output) {

  path <- reactiveValues(
    pth=NULL
  )


  observeEvent(input$filechoose,{
    path$pth <- file.choose()
  })

   output$filechosen <- renderText({

      if(is.null(path$pth)){
        "Nothing selected"
      }else{
        path$pth
      }
   })
}

# Run the application 
shinyApp(ui = ui, server = server)

这就是你想要的吗?

票数 1
EN

Stack Overflow用户

发布于 2019-05-21 07:08:53

谢谢你的例子@MichaelBird。我修改了您的代码,允许用户在不选择文件的情况下取消请求(您的应用程序在取消后崩溃):

顺便说一句,这只适用于PC主机上的闪亮应用程序。

代码语言:javascript
复制
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)

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

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

看这个RStudio 文章

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51191701

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档