r - 获取上传文件的名称作为Shiny中的变量

标签 r file-upload shiny

我正在创建一个 Shiny 的应用程序,其中维恩图的一个部分将以上传的文件命名(由用户完成)。例如,如果有人上传文件 ClientXYZ.csv,维恩图的一部分将被命名为“ClientXYZ”

在 Shiny 中可以做到这一点吗?

最佳答案

如果没有可重现的示例,尚不清楚,但您可以通过输入和名称获取文件的名称。

library(shiny)

ui <- fluidPage(

   titlePanel("Grabbing my file name"),

   sidebarLayout(
      sidebarPanel(
        fileInput('file1', 'Select your file',
                  accept = c(
                    'text/csv',
                    'text/comma-separated-values',
                    '.csv'
                  )
        )
      ),
      mainPanel(
         textOutput("myFileName")
      )
   )
)

server <- function(input, output) {

  file_name <- reactive({
    inFile <- input$file1

    if (is.null(inFile))
      return(NULL)

    return (stringi::stri_extract_first(str = inFile$name, regex = ".*(?=\\.)"))
  })

  output$myFileName <- renderText({ file_name() })

}

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

关于r - 获取上传文件的名称作为Shiny中的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41505423/

相关文章:

python - Python 中的项目功能类似于 RStudio

c++ - Rcpp:将 C 数组作为 NumericMatrix 返回给 R

r - 如何将 y 轴更改为美元格式并避免使用科学记数法?

r - 从下拉列表中选择一个变量并将其作为 R Shiny 中的reactivePlot 中的参数传递

python - 在Python/R中使用SLINK后分离集群

ruby-on-rails - Carrierwave无法删除图像

android - 在上传之前调整从画廊或相机拍摄的图像的大小

javascript - 计算文本区域中加载文件的字符数?

r - Shiny 的下载处理程序超时

javascript - 当在服务器中构建 colorInput 时,R Shiny 使用 javascript 绘制地更新跟踪颜色