我对fileInput的R发亮有一些问题。大小限制设置为每个默认值5MB。因为我必须处理的文件非常大(>50 of ),所以我只需要数据路径和文件的名称。不幸的是,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")
})
})提前感谢
迈克尔
发布于 2018-07-05 13:01:10
下面是一个示例,说明如何在一个闪亮的应用程序中使用file.choose()来获取文件的本地路径(以及文件名):
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)这就是你想要的吗?
发布于 2019-05-21 07:08:53
谢谢你的例子@MichaelBird。我修改了您的代码,允许用户在不选择文件的情况下取消请求(您的应用程序在取消后崩溃):
顺便说一句,这只适用于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)另一种方法是增加上传的最大文件大小:
默认情况下,闪亮限制文件上传到每个文件5MB。可以使用shiny.maxRequestSize选项修改此限制。例如,在app.R的顶部添加选项(shiny.maxRequestSize= 30*1024^2)将使限制增加到30 of。
看这个RStudio 文章。
https://stackoverflow.com/questions/51191701
复制相似问题