我正在创建一个 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/