I've been working on a R Shiny app that uses the content from two folders to perform some analysis and I'm having a hard time working with the reactive expression with the ShinyFiles app.
This is the part that I'm having trouble with:
shinyServer(function(input, output, session) {
volumes = getVolumes()
folderInput1<- reactive({
shinyDirChoose(input, 'directory', roots= volumes, session=session, restrictions=system.file(package='base'))
return(parseDirPath(volumes, input$directory))})
folderInput2<- reactive ({
shinyDirChoose(input, 'directory2', roots=volumes, session=session, restrictions=system.file(package='base'))
return(parseDirPath(volumes, input$directory2 ))})
output$directorypath = renderPrint({folderInput1()})
output$directorypath2 = renderPrint({folderInput2()})
files1 <- list.files(path=folderInput1(), pattern="*.csv", full.names=T)
nFiles1 = length(files1)
files2 <- list.files(path= folderInput2(), pattern="*.csv", full.names=T)
nFiles2 = length(files2)
This is the error message I'm getting: Error in .getReactiveEnvironment()$currentContext() : Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)
When I use the input folder from the user just one time I don't get this error.
THIS PROBLEM WAS SOLVED. Thanks!
Now, I'm having problem while using the reactive expressions in a data structure, like a data frame. For example:
folder_df = data.frame(matrix(0,ncol = 4, nrow = nFiles1()))
I'm getting this error message: Error in matrix(0, ncol = 4, nrow = nFiles1()) : non-numeric matrix extent