0
votes

I have deployed one shiny application on my server using shiny server. The sample example is shown below:

ui.R

#library(shinyjs)
library(shiny)

#filenames <- list.files(path = "data",pattern="\\.csv$")
#names(filenames) <- gsub(pattern = "\\.csv$", "", filenames)
shinyUI(fluidPage(
  titlePanel(
    headerPanel( 
      h3("Testing....",
         align="center", style="bold")
      )
    ),
  br(),
  br(),
  #useShinyjs(),  ## initialize shinyjs to reset input files.
  sidebarLayout(
    sidebarPanel(
      h5("Upload Data Files",style="bold"),
      fileInput("files", 
                "Choose CSV/txt processed files or raw files",
                multiple = "TRUE",
                accept=c('text/csv',
'text/comma-separated-values,
text/plain', '.csv','.cel','.TXT','.txt')),
#selectInput('dataset',"Choose platform annotation file", c("Please select a file" ='',filenames)),
fluidRow(
  column(5,
         radioButtons("radio", label = h5("Data uploaded"),
                      choices = list("Affymetrix" = 1, "Codelink" = 2,
                                     "Illumina" = 3),selected = NULL)
         )
  ),
fluidRow(
  column(10,
         h5("Differential Expression Call", style = "bold"),
         checkboxInput("checkbox",
                       label = "Differential Expression", value = FALSE))),
br(),
uiOutput('AnnotationFile')),
mainPanel(                      
  tabsetPanel(id = "MamgedTabs",
              tabPanel("Source-data", dataTableOutput("sourced")),
              tabPanel("Annotation-data",dataTableOutput("annotation"))
              )
  )
)
)
)

server.R

#library(gcrma)
#library(hgu133a.db)
#library(hgu133acdf)
#library(hgu133plus2.db)
#library(hgu133plus2cdf)
#library(hgu133a2frmavecs)
#library(hgu133b.db)
#library(hgu133bcdf)
#library(hgu219.db)
#library(hgu219cdf)
#library(hgu95a.db)
#library(hgu95acdf)
#library(org.Hs.eg.db)
#library(hgu133a2.db)
#library(hgu133a2cdf)
#library(hgu95av2.db)
#library(hgu95av2cdf)
#library(hgu133plus2cdf)
#library(affyPLM)
##library(makecdfenv)
#library(parallel)
#library(base)
#library(S4Vectors)
#library(IRanges)
#library(stats4)
#library(BiocInstaller)
#library(Biobase)
#library(BiocGenerics)
#library(BiocParallel)
#library(biomaRt)
#library(Biostrings)
#library(preprocessCore)
#library(affyio)
#library(zlibbioc)
#library(graphics)
#library(grDevices)
#library(methods)
#library(genefilter)
#library(stats)
#library(AnnotationDbi)
#library(utils)


## Defining the size of file to be accepted. Here it can accept any size.
options(shiny.maxRequestSize= -1) 

shinyServer(function(input, output,session) {
  filenames <- list.files(path = "data", pattern="\\.txt$")
  names(filenames) <- gsub(pattern = "\\.txt$", "", filenames)


  ## Dropdown box for chosing and loading annotation file
  output$AnnotationFile = renderUI({
    if(!input$checkbox | (input$checkbox == T && input$radio != 2)){
      wellPanel(
        h5("Upload Annotation File"),
        selectInput('dataset', "Choose platform annotation file",
                    c("Please select a file" = '', filenames), multiple = TRUE))
    }
  })
})

As you see in the server.R, I need many packages to be loaded, that takes some time. The below code

output$AnnotationFile = renderUI({
    if(!input$checkbox | (input$checkbox == T && input$radio != 2)){
      wellPanel(
        h5("Upload Annotation File"),
        selectInput('dataset', "Choose platform annotation file",
                    c("Please select a file" = '', filenames), multiple = TRUE))
    }
  })

is to show are hide something, takes some time to appear, because of the time it take to load the packages, but sometimes it does not display at all.

1) My application works fine locally, but shows this behavior, when deployed on the server. Any reason?

2) How can I display a message on the main panel that the application is getting ready till it load all the packages.

Edit: I can display the message inside shinyServer(), but that is for each session(will load all the packages again and again), however I want to show and load all the packages at the start of the application. In other words, it is to say that how to display progression message outside shinyServer()

2
renderPrint might be useful for you and inside that use print method to display your message.Saurabh Chauhan
You could use busyIndicator from the shinysky package. For more information follow this linkSBista

2 Answers

1
votes

If you want your application to wait till all the packages are loaded,you just need to put all the packages in ui.R, the reason is simple, as the ui.R is getting executed before server.R. So you can put all the packages at the top of ui.R. When the application starts, it will load all the packages before showing you the interface that you have coded in ui.R, for example

#library(gcrma)
#library(hgu133a.db)
#library(hgu133acdf)

shinyUI(fluidPage(
# your code...
)
)

As you are using packages in server.R, it will show the application (ui.R part),but internally it will be loading all the packages, that will take some time, which user may not be knowing, eventually may lead to confusing about working of the application. To avoid that ui.R is a good option to have packages.

1
votes

Maybe a progress indicator or a modal dialog is what you want?

UPDATE 2

Here is an elaborated use of a progress bar for reading in a text file of 30 R packages, one per line:

# server.R
options(shiny.maxRequestSize = -1)
shinyServer(function(input, output, session) {
  withProgress(message = "Please wait", value = 0, expr = {
    for (i in 1:30) {
      source(textConnection(readLines("packages.txt", warn = FALSE)[i]))
      incProgress(amount = 1/30, detail = paste0("Loading package ", i, "/30"))
      Sys.sleep(time = 0.1)
    }
  })

  filenames <- list.files(path = "data", pattern = "\\.txt$")
  names(filenames) <- gsub(pattern = "\\.txt$", "", filenames)

  output$AnnotationFile <- renderUI({
    if (!input$checkbox | (input$checkbox == T && input$radio != 2)) {
      wellPanel(
        h5("Upload Annotation File"),
        selectInput('dataset', "Choose platform annotation file", c("Please select a file" = '', filenames), multiple = TRUE)
      )
    }
  })
})