СВЯЗАННЫЕ С: Отобразить путь к выбранной папке в Shiny
Я не могу получить путь к файлу от shinyFileChoose
, чтобы использовать его в другой функции. Я пробовал следующий подход в соответствии с руководством и связанной веткой, упомянутой выше, но я все еще ничего не получил ...
Мне просто нужен абсолютный путь к файлу, который выбирает пользователь, чтобы я мог использовать его в своей программе позже (в нескольких различных функциях).
ui <- fluidPage(
titlePanel("File Browser"),
sidebarLayout(
sidebarPanel(
shinyFilesButton('files', label = 'Select', title = 'Please select a
file', multiple = FALSE),
verbatimTextOutput("filechosen")
),
mainPanel(
)
)
)
server <- function(input, output) {
shinyFileChoose(input, 'files', root = c(root = '/home/guest/test_data'),
filetypes = c('', "xml", "txt"))
file <- reactive(input$files)
output$filechosen <- renderText({
parseFilePaths(c(home = "/home/guest/test_data"), file())
})
}
shinyApp(ui = ui, server = server)
Error: argument 1 (type 'list') cannot be handled by 'cat'
поскольку вывод parseFilePaths
представляет собой однострочную dataframe
, вы должны указать столбец и изменить его на character
, чтобы он мог отображаться в renderText
.
Пытаться :
library(shinyFiles)
ui <- fluidPage(
titlePanel("File Browser"),
sidebarLayout(
sidebarPanel(
shinyFilesButton('files', label = 'Select', title = 'Please select a
file', multiple = FALSE),
verbatimTextOutput("filechosen")
),
mainPanel(
)
)
)
server <- function(input, output) {
shinyFileChoose(input, 'files', root = c(root = '/home/guest/test_data'),
filetypes = c('', "xml", "txt"))
file <- reactive(input$files)
output$filechosen <- renderText({
as.character(parseFilePaths(c(home = "/home/guest/test_data"),file())$datapath)
# Either is fine
# parseFilePaths(c(home = "/home/guest/test_data"),file())$datapath,stringAsFactors=F)
})
}
shinyApp(ui = ui, server = server)