Reputation: 75
I would like to browse for files in R Shiny and open them in Microsoft Excel. I don't want to read them into R Shiny with read_exel or similar.
For now, I have a code to read in the files and display them in Shiny:
I already have a panel to browse the files:
sidebarPanel(fileInput('browseFiles', 'View test description')
),
mainPanel(
tableOutput("inputFile")
)
and a function:
output$inputFile <- renderTable({
inFile <- input$browseFiles
if (is.null(inFile))
return(NULL)
read_excel(inFile$datapath, col_names = T, skip = 2)
})
any help would be appreciated
Upvotes: 0
Views: 202
Reputation: 75
I managed to solve the problem - thanks Sirius!
sidebarPanel(shinyFilesButton('browseFiles', 'View', 'Select file', multiple = F)),
and
# Browse files with test description
shinyFileChoose(input, 'browseFiles', root = c(Tests = pathTests), session = session,
defaultRoot = NULL,
# defaultPath = pathTests,
filetypes=c('', 'xlsx'))
observe({
#print(input$browseFiles)
# find path to data
if(!is.integer(input$browseFiles)){
p = parseFilePaths(roots = c(Tests = pathTests), input$browseFiles)
# open the file
if (.Platform$OS.type == "unix"){
system(paste('open', as.character(p$datapath)))
} else if (.Platform$OS.type == "windows"){
system(as.character(p$datapath))
}
}
})
Upvotes: 1