gpt4 book ai didi

R shiny file输入大文件

转载 作者:行者123 更新时间:2023-12-02 03:33:13 25 4
gpt4 key购买 nike

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

如何只交出我的应用路径而不上传文件?

ui.R

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

# 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")
})
})

提前致谢

迈克尔

最佳答案

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

顺便说一句,这只适用于托管 shiny 应用程序的 PC。

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)

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

By default, Shiny limits file uploads to 5MB per file. You can modify this limit by using the shiny.maxRequestSize option. For example, adding options(shiny.maxRequestSize = 30*1024^2) to the top of app.R would increase the limit to 30MB.

查看此 RStudio article .

关于R shiny file输入大文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51191701/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com