I am building a Shiny app that automates running of one of my R packages. The intent is to include the app in my package itself, as well as through shiny apps.io.
I think I am near a solution, but am experiencing one issue.
In my package, I have the line
seqs <- ape::read.dna(file = file.choose(), format = "fasta")
which works locally, but not through the browser (as expected).
My attempt to fix this is by using shiny::FileInput()
.
I now have included the following lines within my R package:
if (interactive()) {
seqs <- ape::read.dna(file = file.choose(), format = "fasta")
} else {
seqs <- ape::read.dna(file = some.path, format = "fasta")
}
Here's the code specific code snippet in ui.R:
fileInput(inputId = "fastafile",
label = "Choose a FASTA file",
accept = c(".fas", ".fasta"),
buttonLabel = "Browse...")
and that for server.R:
fasta <- input$fastafile
ext <- tools::file_ext(fasta$datapath)
req(fasta)
validate(need(ext == c("fas", "fasta"), "Please upload a FASTA file"))
seqs <- ape::read.dna(file = fasta$datapath, format = "fasta")
However, when I publish the app online, I get the error
character(0)
An error has occurred. Check your logs or contact the app author for clarification.
The specific error in the logs is:
Warning in file(con, "rb") : cannot open file '��A�U': No such file or directory
Warning: Error in file: cannot open the connection
Why doesn't this solution work?
Does anyone have any ideas on how to solve the problem?