Dan*_*man 1 javascript r http shiny shiny-server
有没有办法在不将文件上传到 R Shiny 的情况下“查看”文件大小?
根据@ismirsehregal提供的建议,我们可以修改fileInput
并添加一些JS来实现您的目标。
library(shiny)
ui <- fluidPage(
fileInput("check", NULL, buttonLabel = "Upload to check", placeholder = "Check File Size"),
# remove progress bar since we are not truely uploading
tags$style("#check .shiny-file-input-progress {display: none}"),
tags$script(
"
$('#check').on('change', function() {
$(this)
.parents('div.input-group')
.find('.form-control')
.attr('placeholder', `File size is ${this.files[0].size}`); // update text
// If you want R server to also know the size, we can set up an input
Shiny.setInputValue('check_size', this.files[0].size)
$(this).val(''); // this prevents shiny to takeover the file and upload the file
});
"
)
)
server <- function(input, output, session) {
observe(print(input$check_size))
}
shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud)
这将为您提供 UI 和服务器上的文件大小。希望这是你想要的。