problem with Shiny update 1.0 to 1.2 ?

Hi everybody,

I'm a newbie with shiny package but I must continue a project with a pipeline scripted in R + shiny.
The pipeline was written and runs with R 3.4.3 and shiny 1.0.5.
On my computer, R is 3.5.1 and shiny 1.2.0 and the pipeline aborts quickly...

Main steps of the pipeline :

  • select the repertory to put the results -> it's written on the shiny webpage when selected
  • select the repertory where are data used by the pipeline -> it's written on the shiny webpage when selected
  • select which analysis to run : I put only one for the forum
  • launch of the analysis

I simplify the scientific analysis with a easy test :
for each file in the data subdirectory, do
add the name of file with full path in a new file in the result folder
end_for

Here is the code (light version) of the first part of the pipeline :

library(shiny)
packages <- c("data.table", "Biostrings", "ggplot2", "ggridges", "plyr", "reshape2", "rstudioapi", "scales",
             "shinyBS", "shinycssloaders","shinyFiles", "shinyjs", "tidyr", "viridis", "viridisLite", "yaml")
# shinyBS = shiny Bootstrap Controls as bsTooltip
## If a package if not available, install it.
if (length(setdiff(packages, rownames(installed.packages()))) > 0) {
 install.packages(setdiff(packages, rownames(installed.packages())))}
#Load the packages
lapply(packages, require, character.only = TRUE)

# /***** Define UI for app  *****/
ui <- fluidPage(
  ## App title
  titlePanel(title ="My_pipeline"),
 
  ## ask for main directory
  sidebarLayout(
    sidebarPanel(shinyDirButton("nanopath", "Main directory", "Please choose main directory")),
    mainPanel(h4("Main directory"),
              verbatimTextOutput("nanopath", placeholder = TRUE))),
  ## tooltip for main directory
  bsTooltip('nanopath', "The folder where you save the outcome of Nanoflow.", placement="top"),

  ## ask for fast5 raw directory
  sidebarLayout( #
   sidebarPanel(shinyDirButton("rawFast5Dir", "Fast5 raw directory", "Please choose Fast5 raw directory")),
   mainPanel(h4("Fast5 raw directory"),
             verbatimTextOutput("rawFast5Dir", placeholder = TRUE))),
  ## tooltip for fast5 raw directory
  bsTooltip('rawFast5Dir', "A Fast5 folder created during the MinION run.", placement="top"),
  ## set the launch button
  sidebarLayout(
    sidebarPanel(
      actionButton("goButton", "Launch!"),
      p("Click to start the analysis.")),
    mainPanel(
      h5(textOutput("progress.1", container = span)))),
  ## ask for input (analysis type)
  column(4,
         selectInput("workflow", h3("Select Analysis"),
                     choices = list("Basecalling"),
                     selected = 1))
)
# /***** end of UI *****/

# /***** Define server for app *****/
server <- function(input, output) {
  ## Set Main directory path
  shinyDirChoose(input, "nanopath", roots = c(home = '~'), filetypes = c('', 'txt')) # show only *.txt files
  nanopath <- reactive(input$nanopath) ## Get the path
  output$nanopath <- renderText({  ## Display the path
    parseDirPath(c(home = '~'), nanopath())
  })

  ## Set the working directory
  observeEvent(ignoreNULL = TRUE,
    eventExpr = {
      input$nanopath
    },
    handlerExpr = {
      home <- normalizePath("~")
      nanodir <<- file.path(home, paste(unlist(nanopath()$path), collapse = .Platform$file.sep))
      setwd(nanodir)
    }
  )

  ## Set the Fast5dir path -- original code --
  shinyDirChoose(input, 'rawFast5Dir', roots = c(home = '~'), filetypes = c('', 'txt'))
  rawFast5Dir <- reactive(input$rawFast5Dir) ## Get the path
  output$rawFast5Dir <- renderText({  ## Display the path
    parseDirPath(c(home = '~'), rawFast5Dir())
  })
  ## Set the fast5 and basecalled directories
  observeEvent(ignoreNULL = TRUE,
    eventExpr = {
      input$rawFast5Dir
    },
    handlerExpr = {
      home <- normalizePath("~")
      fast5path <<- file.path(home, paste(unlist(rawFast5Dir()$path[-1]), collapse = .Platform$file.sep))
      basecalledDir <<- paste(nanodir, "/basecalled",sep='') # gsub('(.*)/\\w+', '\\1'
    }
  )
 
  ## clicking button. The outcome will depend of the chosen options
  observeEvent(input$goButton, {
    if(input$workflow == 'Basecalling'){
      withProgress(message = 'Basecalling', value = 0, {
        # Number of times we'll go through the loop
        n <- as.numeric(system(paste('ls -d ', fast5path, '/*/ | wc -l', sep=""), intern = TRUE))
        system(paste('mkdir -p ', basecalledDir, sep=''))
        fast5folders <- system(paste('ls -d ', fast5path, '/*/ ', sep=""), intern = TRUE)
       fast5folders<- substr(fast5folders, 1, nchar(fast5folders)-1)
       for(i in fast5folders){
         incProgress(1/n, detail = paste("Processing folder ", basename(i)))
         system(paste('echo ',i, ' >> ', basecalledDir, '/toto.txt', sep='' ))
        }
      })
      output$progress.1 <- renderText({
        paste("Basecalling finished at ", Sys.time(), ". Basecalled fast5 files were saved to: ", basecalledDir, sep="")
      })
    }
  })
}
# /***** end of server *****/

# /***** run app *****/
shinyApp(ui = ui, server = server)

I haven't no error message or warning when I run it with with R 3.4.3 and shiny 1.0.5.
But here is the error message when I run on my computer (R is 3.5.1 and shiny 1.2.0):
Warning: Error in $: $ operator is invalid for atomic vectors 79: unlist 72: observeEventHandler [/Users/1234/Documents/work/byPeople/Emma/app-NanoFlow-EB/app.R#84]

And I can't select any folder.

After google/forum searchs, I found that with the shiny v.1.2, I need to precise the type of my value in the both handleExp with req() like this :

handlerExpr = {
      req(is.list(nanopath)) ## new v.1.2
      home <- normalizePath("~")
      nanodir <<- file.path(home, paste(unlist(nanopath()$path), collapse = .Platform$file.sep))
      setwd(nanodir)
    }

and

handlerExpr = {
      req(is.list(rawFast5Dir)) ## new v.1.2
      home <- normalizePath("~")
      fast5path <<- file.path(home, paste(unlist(rawFast5Dir()$path[-1]), collapse = .Platform$file.sep))
      basecalledDir <<- paste(nanodir, "/basecalled",sep='') # gsub('(.*)/\\w+', '\\1'
    }

If I test : the webpage is grey and I have a new error message :
Warning: Error in eval: objet 'fast5path' introuvable 81: eval 80: eval 78: standardGeneric 77: paste 72: observeEventHandler [/Users/1234/Documents/work/byPeople/Emma/app-NanoFlow-EB/app.R#112]

Furthermore, during a test (on my computer), I had a error message, something like setwd() : couldn't change the working directory. Is it related to the previous problem? arg... and it's only the beginning ot the pipeline.... :-/

Could anyone help me, please ? Thanks a lot!

Emma

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.