daattali / shinycssloaders

⌛ Add loading animations to a Shiny output while it's recalculating
https://daattali.com/shiny/shinycssloaders-demo/
Other
395 stars 45 forks source link

withSpinner() removes reactive element of uploading data and selecting column names #41

Closed mattlee821 closed 4 years ago

mattlee821 commented 4 years ago

Issue related to my post on Stack Overflow recently. In short, when uploading data to my shiny app, drop down lists should be populated with the column names of the uploaded data frame. This worked on 23/01/2020. As of 24/01/2020 the column names no longer populated the drop down lists. I found that removing withSpinner() from my ui.R fixed this issue. I know a recent update was pushed so wondering if this broke the app or if something else is going on where removing withSpinner() is allowing reactivity to work within the Shiny app.

Thanks!

ismirsehregal commented 4 years ago

Very interesting. I'm having a similar issue. After updating to shinycssloaders version 0.3 the choices of my selectizeInput's in some of my apps were no longer populated (the choices should be loaded from .rds files - it seemed the UI rendering was blocked). I switched to addSpinner() from shinyWidgets by now, which is working fine.

daattali commented 4 years ago

Is this potentially related to #39? Could you try to do what I suggested in this comment to see if it's affected by the same issue?

mattlee821 commented 4 years ago

I've put withSpinner() back in and tried the following as suggested in #39

Using remotes::install_github("andrewsali/shinycssloaders", ref="8779ff0f0ad32b0731c06067e35fa65d85f66a89") leads to a working app.

Using remotes::install_github("andrewsali/shinycssloaders", ref="9565546494f3395a257546312313929ec0bbf968") leads to a working app

Using install.packages("shinycssloaders") leads to a broken app

Using remotes::install_github("andrewsali/shinycssloaders") leads to a broken app

daattali commented 4 years ago

Do you have a small reproducible sample code that you used for these tests?

mattlee821 commented 4 years ago

I've copied straight from the app as minimally as I can get to reproduce. Line 215 has withSpinner() on.

data <- data.frame(this = 1:10, is = 1:10, some = 1:10, great = 1:10, example = 1:10, data = 1:10)
write.table(data, "/Users/ml16847/Downloads/data_frame.txt", 
            row.names = FALSE, col.names = TRUE, quote = FALSE, sep = "\t")

# load libraries ====
library(shiny)
library(shinydashboard)
library(shinyLP)
library(shinythemes)
library(plotly)
library(ggplot2)
library(data.table)
library(circlize)
library(dplyr)
library(stringr)
library(fs)
library(rmarkdown)
library(markdown)
library(data.table)

install.packages("shinycssloaders")
library(shinycssloaders)

#------------------------------------------------------------------------------#

ui <- navbarPage(
  title = "",
  theme = shinytheme("flatly"),
  fluid = TRUE,
  selected = "MR Viz",
  inverse = FALSE,

  # ANALYSIS ====
  tabPanel(title = "Analysis",

           ## UPLOAD YOUR DATA ====
           tabPanel(titlePanel(h5("Step 1")),
                    sidebarLayout(
                      ## > sidebar panel ====
                      sidebarPanel(
                        helpText("Select paramaters for data upload then upload data. Functions based on R read.table()."),

                        checkboxInput(
                          inputId = 'header',
                          label = 'Header',
                          value = TRUE
                        ),

                        checkboxInput(inputId = "stringAsFactors", "stringAsFactors", FALSE),

                        radioButtons(
                          inputId = 'sep',
                          label = 'Separator',
                          choices = c(
                            Comma = ',',
                            Semicolon = ';',
                            Tab = '\t',
                            Space = ''
                          ),
                          selected = '\t'
                        ),

                        radioButtons(
                          inputId = "quote",
                          label = "Quote",
                          choices = c(
                            None = "",
                            "Double Quote" = '"',
                            "Single Quote" = "'"
                          ),
                          selected = '"'
                        ),

                        fileInput(
                          inputId = "file1",
                          label = "Track 1",
                          multiple = TRUE,
                          accept = c(
                            "text/csv",
                            "text/comma-separated-values",
                            "text/plain",
                            ".csv"
                          )
                        ),

                        fileInput(
                          inputId = "file2",
                          label = "Track 2",
                          multiple = TRUE,
                          accept = c(
                            "text/csv",
                            "text/comma-separated-values",
                            "text/plain",
                            ".csv"
                          )
                        ),

                        fileInput(
                          inputId = "file3",
                          label = "Track 3",
                          multiple = TRUE,
                          accept = c(
                            "text/csv",
                            "text/comma-separated-values",
                            "text/plain",
                            ".csv")
                        ),

                        helpText("Select paramaters for Circos plot"),

                        selectInput("track_number",
                                    "Number of tracks",
                                    choices = c(1,2,3),
                                    selected = 1),
                        selectInput("label_column",
                                    "Label:",
                                    choices="", 
                                    selected = ""),
                        selectInput("section_column",
                                    "Group:",
                                    choices="",
                                    selected = ""),
                        selectInput("estimate_column",
                                    "Estimate:",
                                    choices="",
                                    selected = ""),
                        selectInput("pvalue_column",
                                    "P-value:",
                                    choices="",
                                    selected = ""),
                        numericInput("pvalue_adjustment",
                                     "P-value adjustment:",
                                     value = 123),
                        textOutput("pval"),
                        br(),
                        selectInput("confidence_interval_lower_column",
                                    "Lower confidence interval:",
                                    choices="",
                                    selected = ""),
                        selectInput("confidence_interval_upper_column",
                                    "Upper confidence interval:",
                                    choices="",
                                    selected = ""),
                        h4("Legend paramaters"),
                        radioButtons(
                          inputId = 'legend',
                          label = 'Legend',
                          choices = c(
                            Yes = 'TRUE',
                            No = 'FALSE'),
                          selected = 'FALSE'),
                        textInput("track2_label",
                                  "Track 2 legend label",
                                  value = "Example1"),
                        textInput("track3_label",
                                  "Track 3 legend label",
                                  value = "Example2"),
                        textInput("track4_label",
                                  "Track 4 legend label",
                                  value = "Example3"),
                        textInput("pvalue_label",
                                  "P-value threshold label",
                                  value = "P > 123"),
                        textOutput("pval_label"),
                        br(),
                        actionButton("circosbutton","Plot")
                      ),

                      ## > main panel ====
                      mainPanel(
                        tabsetPanel(
                          tabPanel("Track 1",  
                                   conditionalPanel(
                                     condition = "output.file_imported",
                                     h4("Description of uploaded data"),
                                     textOutput("rowcount"),
                                     textOutput("colcount"),
                                     br(),
                                     h4("First rows of uploaded data"),
                                     tableOutput(outputId = "data1"),
                                     br(),
                                     h4("Volcano plot of uploaded data"),
                                     plotlyOutput("volcanoplot1")
                                   )),

                          tabPanel("Track 2",  
                                   conditionalPanel(
                                     condition = "output.file_imported2",
                                     h4("Description of uploaded data"),
                                     textOutput("rowcount2"),
                                     textOutput("colcount2"),
                                     br(),
                                     h4("First rows of uploaded data"),
                                     tableOutput(outputId = "data2"),
                                     br(),
                                     h4("Volcano plot of uploaded data"),
                                     plotlyOutput("volcanoplot2")
                                   )),

                          tabPanel("Track 3",  
                                   conditionalPanel(
                                     condition = "output.file_imported3",
                                     h4("Description of uploaded data"),
                                     textOutput("rowcount3"),
                                     textOutput("colcount3"),
                                     br(),
                                     h4("First rows of uploaded data"),
                                     tableOutput(outputId = "data3"),
                                     br(),
                                     h4("Volcano plot of uploaded data"),
                                     plotlyOutput("volcanoplot3")
                                   )),
                          tabPanel(withSpinner(uiOutput("pdf")))
                        )
                      )
                    )
           )
  )
)

#------------------------------------------------------------------------------#

server <- shinyServer(function(input, output, session) {

  # HOME ====
  # Download example dataset
  output$downloadexampledata1 <- downloadHandler(
    filename = function() {
      paste0("exampledata1.txt")
    },
    content = function(file) {
      file.copy("exampledata1.txt", file)
    },
    contentType = NA
  )

  output$downloadexampledata2 <- downloadHandler(
    filename = function() {
      paste0("exampledata2.txt")
    },
    content = function(file) {
      file.copy("exampledata2.txt", file)
    },
    contentType = NA
  )

  output$downloadexampledata3 <- downloadHandler(
    filename = function() {
      paste0("exampledata3.txt")
    },
    content = function(file) {
      file.copy("exampledata3.txt", file)
    },
    contentType = NA
  )

  # ANALYSIS ====
  #  UPLOAD YOUR DATA ====
  # > sidebar panel ====
  # Read data from multiple .csv/.txt files
  track2_data1 <- eventReactive(input$file1, {
    rbindlist(
      lapply(
        input$file1$datapath,
        FUN = read.csv,
        header = input$header,
        sep = input$sep,
        quote = input$quote
      ),
      use.names = TRUE,
      fill = TRUE
    )
  })

  track3_data1 <- eventReactive(input$file2, {
    rbindlist(
      lapply(
        input$file2$datapath,
        FUN = read.csv,
        header = input$header,
        sep = input$sep,
        quote = input$quote
      ),
      use.names = TRUE,
      fill = TRUE
    )

  })

  track4_data1 <- eventReactive(input$file3, {
    rbindlist(
      lapply(
        input$file3$datapath,
        FUN = read.csv,
        header = input$header,
        sep = input$sep,
        quote = input$quote
      ),
      use.names = TRUE,
      fill = TRUE
    )

  })

  # > main panel ====
  # >> Track 1 ====
  # Define conditional element to show main panel only when file(s) uploaded
  output$file_imported <- reactive({
    return(!is.null(input$file1))
  })

  outputOptions(output, "file_imported", suspendWhenHidden = FALSE)

  # Create data to describe the imported dataset
  output$rowcount <-
    renderText(paste("Total number of rows in uploaded file(s):", nrow(track2_data1())))
  output$colcount <-
    renderText(paste("Total number of columns in uploaded file(s):", ncol(track2_data1())))

  # Render head of imported dataset
  output$data1 <- renderTable({
    track2_data1() %>% head
  })

  # Render volcano plot
  observeEvent(input$file1,
               handlerExpr = {
                 output$volcanoplot1 <- renderPlotly({
                   volcanoplot <- plot_ly(
                     data = track2_data1(),
                     type = "scatter",
                     colors = NULL,
                     alpha = NULL,
                     x = track2_data1()$beta,
                     y = -log10(track2_data1()$Pvalue),
                     text = track2_data1()$outcome_name,
                     mode = "markers"
                   ) %>%
                     layout(xaxis = list(title = "effect_estimate"),
                            yaxis = list(title = "-log10(p-value)"))
                 })
               })

  # >> Track 2 ====
  # Define conditional element to show main panel only when file(s) uploaded
  output$file_imported2 <- reactive({
    return(!is.null(input$file2))
  })

  outputOptions(output, "file_imported2", suspendWhenHidden = FALSE)

  # Create data to describe the imported dataset
  output$rowcount2 <-
    renderText(paste("Total number of rows in uploaded file(s):", nrow(track3_data1())))
  output$colcount2 <-
    renderText(paste("Total number of columns in uploaded file(s):", ncol(track3_data1())))

  # Render head of imported dataset
  output$data2 <- renderTable({
    track3_data1() %>% head
  })

  # Render volcano plot
  observeEvent(input$file2,
               handlerExpr = {
                 output$volcanoplot2 <- renderPlotly({
                   volcanoplot <- plot_ly(
                     data = track3_data1(),
                     type = "scatter",
                     colors = NULL,
                     alpha = NULL,
                     x = track3_data1()$beta,
                     y = -log10(track3_data1()$Pvalue),
                     text = track3_data1()$outcome_name,
                     mode = "markers"
                   ) %>%
                     layout(xaxis = list(title = "effect_estimate"),
                            yaxis = list(title = "-log10(p-value)"))
                 })
               })

  # >> Track 3 ====
  # Define conditional element to show main panel only when file(s) uploaded
  output$file_imported3 <- reactive({
    return(!is.null(input$file3))
  })

  outputOptions(output, "file_imported3", suspendWhenHidden = FALSE)

  # Create data to describe the imported dataset
  output$rowcount3 <-
    renderText(paste("Total number of rows in uploaded file(s):", nrow(track4_data1())))
  output$colcount3 <-
    renderText(paste("Total number of columns in uploaded file(s):", ncol(track4_data1())))

  # Render head of imported dataset
  output$data3 <- renderTable({
    track4_data1() %>% head
  })

  # Render volcano plot
  observeEvent(input$file3,
               handlerExpr = {
                 output$volcanoplot3 <- renderPlotly({
                   volcanoplot <- plot_ly(
                     data = track4_data1(),
                     type = "scatter",
                     colors = NULL,
                     alpha = NULL,
                     x = track4_data1()$beta,
                     y = -log10(track4_data1()$Pvalue),
                     text = track4_data1()$outcome_name,
                     mode = "markers"
                   ) %>%
                     layout(xaxis = list(title = "effect_estimate"),
                            yaxis = list(title = "-log10(p-value)"))
                 })
               })

  # CIRCOS PARAMETERS ====
  # > sidebar panel ====

  output$pval <- renderText(paste0("New threshold: 0.05/", input$pvalue_adjustment, " = ", round(0.05/input$pvalue_adjustment, digits = 8))
  )
  output$pval_label <- renderText(paste0("P > 0.05/", input$pvalue_adjustment))

  # When the first file is uploaded, pass the column headings to the selectInput widgets
  observeEvent(input$file1, {
    updateSelectInput(session,
                      "label_column",
                      choices = c("",colnames(track2_data1())))

    updateSelectInput(session,
                      "section_column",
                      choices = c("",colnames(track2_data1())))  

    updateSelectInput(session,
                      "estimate_column",
                      choices = c("",colnames(track2_data1())))  

    updateSelectInput(session,
                      "pvalue_column",
                      choices = c("",colnames(track2_data1())))  

    updateSelectInput(session,
                      "confidence_interval_lower_column",
                      choices = c("",colnames(track2_data1()))) 

    updateSelectInput(session,
                      "confidence_interval_upper_column",
                      choices = c("",colnames(track2_data1()))) 

  }
  )

  # Because the my_circos_plot() function expects a column number rather than name,
  # which is what the selectInput widgets return, use the following functions to convert the 
  # column name into the column number
  label_column_number <- reactive({which(colnames(track2_data1())==input$label_column)})
  section_column_number <- reactive({which(colnames(track2_data1())==input$section_column)})
  estimate_column_number <- reactive({which(colnames(track2_data1())==input$estimate_column)})
  pvalue_column_number <- reactive({which(colnames(track2_data1())==input$pvalue_column)})
  confidence_interval_lower_column_number <- reactive({which(colnames(track2_data1())==input$confidence_interval_lower_column)})
  confidence_interval_upper_column_number <- reactive({which(colnames(track2_data1())==input$confidence_interval_upper_column)})

  output$pdf <- renderUI({
    if(file.exists(outfile)){
      tags$iframe(src=outfile,style="height:600px; width:100%")}
  })

  outfile <- tempfile("myfile", fileext = ".pdf", tmpdir ="www")

  observeEvent(input$circosbutton,
               handlerExpr = {
                 output$pdf <- renderUI({
                   pdf(outfile, width = 35, height = 35, pointsize = 30)
                   isolate({
                     my_circos_plot(
                       track_number = input$track_number,
                       track2_data1 = track2_data1(),
                       track3_data1 = track3_data1(),
                       track4_data1 = track4_data1(),
                       section_column = section_column_number(), # This returns the column number, as defined above.
                       label_column = label_column_number(),
                       estimate_column = estimate_column_number(),
                       pvalue_column = pvalue_column_number(),
                       pvalue_adjustment = (0.05/input$pvalue_adjustment),
                       confidence_interval_lower_column = confidence_interval_lower_column_number(),
                       confidence_interval_upper_column = confidence_interval_upper_column_number(),
                       legend = input$legend,
                       track2_label = input$track2_label,
                       track3_label = input$track3_label,
                       track4_label = input$track4_label,
                       pvalue_label = input$pvalue_label)
                   })

                   dev.off()
                   if(file.exists(outfile)){
                     tags$iframe(src=str_sub(outfile,5),style="height:800px; width:100%")}
                 })
               })

  # Return a list containing the filename

  onStop(function() {
    unlink(outfile, recursive = TRUE)
  })

  # > main panel ====

  # Keep shiny app awake ====
  output$keepAlive <- renderText({
    req(input$count)
    paste("keep alive ", input$count)
  })

})

#------------------------------------------------------------------------------#

shinyApp(ui = ui, server = server)
daattali commented 4 years ago

Could you try to shorten that to a ~20 line app that only contains the essentials for seeing the issue?

On Mon., Jan. 27, 2020, 02:17 matt, notifications@github.com wrote:

I've copied straight from the app as minimally as I can get to reproduce. Line 215 has withSpinner() on.

data <- data.frame(this = 1:10, is = 1:10, some = 1:10, great = 1:10, example = 1:10, data = 1:10) write.table(data, "/Users/ml16847/Downloads/data_frame.txt", row.names = FALSE, col.names = TRUE, quote = FALSE, sep = "\t")

load libraries ====

library(shiny) library(shinydashboard) library(shinyLP) library(shinythemes) library(plotly) library(ggplot2) library(data.table) library(circlize) library(dplyr) library(stringr) library(fs) library(rmarkdown) library(markdown) library(data.table)

install.packages("shinycssloaders") library(shinycssloaders)

------------------------------------------------------------------------------

ui <- navbarPage( title = "", theme = shinytheme("flatly"), fluid = TRUE, selected = "MR Viz", inverse = FALSE,

ANALYSIS ====

tabPanel(title = "Analysis",

       ## UPLOAD YOUR DATA ====
       tabPanel(titlePanel(h5("Step 1")),
                sidebarLayout(
                  ## > sidebar panel ====
                  sidebarPanel(
                    helpText("Select paramaters for data upload then upload data. Functions based on R read.table()."),

                    checkboxInput(
                      inputId = 'header',
                      label = 'Header',
                      value = TRUE
                    ),

                    checkboxInput(inputId = "stringAsFactors", "stringAsFactors", FALSE),

                    radioButtons(
                      inputId = 'sep',
                      label = 'Separator',
                      choices = c(
                        Comma = ',',
                        Semicolon = ';',
                        Tab = '\t',
                        Space = ''
                      ),
                      selected = '\t'
                    ),

                    radioButtons(
                      inputId = "quote",
                      label = "Quote",
                      choices = c(
                        None = "",
                        "Double Quote" = '"',
                        "Single Quote" = "'"
                      ),
                      selected = '"'
                    ),

                    fileInput(
                      inputId = "file1",
                      label = "Track 1",
                      multiple = TRUE,
                      accept = c(
                        "text/csv",
                        "text/comma-separated-values",
                        "text/plain",
                        ".csv"
                      )
                    ),

                    fileInput(
                      inputId = "file2",
                      label = "Track 2",
                      multiple = TRUE,
                      accept = c(
                        "text/csv",
                        "text/comma-separated-values",
                        "text/plain",
                        ".csv"
                      )
                    ),

                    fileInput(
                      inputId = "file3",
                      label = "Track 3",
                      multiple = TRUE,
                      accept = c(
                        "text/csv",
                        "text/comma-separated-values",
                        "text/plain",
                        ".csv")
                    ),

                    helpText("Select paramaters for Circos plot"),

                    selectInput("track_number",
                                "Number of tracks",
                                choices = c(1,2,3),
                                selected = 1),
                    selectInput("label_column",
                                "Label:",
                                choices="",
                                selected = ""),
                    selectInput("section_column",
                                "Group:",
                                choices="",
                                selected = ""),
                    selectInput("estimate_column",
                                "Estimate:",
                                choices="",
                                selected = ""),
                    selectInput("pvalue_column",
                                "P-value:",
                                choices="",
                                selected = ""),
                    numericInput("pvalue_adjustment",
                                 "P-value adjustment:",
                                 value = 123),
                    textOutput("pval"),
                    br(),
                    selectInput("confidence_interval_lower_column",
                                "Lower confidence interval:",
                                choices="",
                                selected = ""),
                    selectInput("confidence_interval_upper_column",
                                "Upper confidence interval:",
                                choices="",
                                selected = ""),
                    h4("Legend paramaters"),
                    radioButtons(
                      inputId = 'legend',
                      label = 'Legend',
                      choices = c(
                        Yes = 'TRUE',
                        No = 'FALSE'),
                      selected = 'FALSE'),
                    textInput("track2_label",
                              "Track 2 legend label",
                              value = "Example1"),
                    textInput("track3_label",
                              "Track 3 legend label",
                              value = "Example2"),
                    textInput("track4_label",
                              "Track 4 legend label",
                              value = "Example3"),
                    textInput("pvalue_label",
                              "P-value threshold label",
                              value = "P > 123"),
                    textOutput("pval_label"),
                    br(),
                    actionButton("circosbutton","Plot")
                  ),

                  ## > main panel ====
                  mainPanel(
                    tabsetPanel(
                      tabPanel("Track 1",
                               conditionalPanel(
                                 condition = "output.file_imported",
                                 h4("Description of uploaded data"),
                                 textOutput("rowcount"),
                                 textOutput("colcount"),
                                 br(),
                                 h4("First rows of uploaded data"),
                                 tableOutput(outputId = "data1"),
                                 br(),
                                 h4("Volcano plot of uploaded data"),
                                 plotlyOutput("volcanoplot1")
                               )),

                      tabPanel("Track 2",
                               conditionalPanel(
                                 condition = "output.file_imported2",
                                 h4("Description of uploaded data"),
                                 textOutput("rowcount2"),
                                 textOutput("colcount2"),
                                 br(),
                                 h4("First rows of uploaded data"),
                                 tableOutput(outputId = "data2"),
                                 br(),
                                 h4("Volcano plot of uploaded data"),
                                 plotlyOutput("volcanoplot2")
                               )),

                      tabPanel("Track 3",
                               conditionalPanel(
                                 condition = "output.file_imported3",
                                 h4("Description of uploaded data"),
                                 textOutput("rowcount3"),
                                 textOutput("colcount3"),
                                 br(),
                                 h4("First rows of uploaded data"),
                                 tableOutput(outputId = "data3"),
                                 br(),
                                 h4("Volcano plot of uploaded data"),
                                 plotlyOutput("volcanoplot3")
                               )),
                      tabPanel(withSpinner(uiOutput("pdf")))
                    )
                  )
                )
       )

) )

------------------------------------------------------------------------------

server <- shinyServer(function(input, output, session) {

HOME ====

Download example dataset

output$downloadexampledata1 <- downloadHandler( filename = function() { paste0("exampledata1.txt") }, content = function(file) { file.copy("exampledata1.txt", file) }, contentType = NA )

output$downloadexampledata2 <- downloadHandler( filename = function() { paste0("exampledata2.txt") }, content = function(file) { file.copy("exampledata2.txt", file) }, contentType = NA )

output$downloadexampledata3 <- downloadHandler( filename = function() { paste0("exampledata3.txt") }, content = function(file) { file.copy("exampledata3.txt", file) }, contentType = NA )

ANALYSIS ====

UPLOAD YOUR DATA ====

> sidebar panel ====

Read data from multiple .csv/.txt files

track2_data1 <- eventReactive(input$file1, { rbindlist( lapply( input$file1$datapath, FUN = read.csv, header = input$header, sep = input$sep, quote = input$quote ), use.names = TRUE, fill = TRUE ) })

track3_data1 <- eventReactive(input$file2, { rbindlist( lapply( input$file2$datapath, FUN = read.csv, header = input$header, sep = input$sep, quote = input$quote ), use.names = TRUE, fill = TRUE )

})

track4_data1 <- eventReactive(input$file3, { rbindlist( lapply( input$file3$datapath, FUN = read.csv, header = input$header, sep = input$sep, quote = input$quote ), use.names = TRUE, fill = TRUE )

})

> main panel ====

>> Track 1 ====

Define conditional element to show main panel only when file(s) uploaded

output$file_imported <- reactive({ return(!is.null(input$file1)) })

outputOptions(output, "file_imported", suspendWhenHidden = FALSE)

Create data to describe the imported dataset

output$rowcount <- renderText(paste("Total number of rows in uploaded file(s):", nrow(track2_data1()))) output$colcount <- renderText(paste("Total number of columns in uploaded file(s):", ncol(track2_data1())))

Render head of imported dataset

output$data1 <- renderTable({ track2_data1() %>% head })

Render volcano plot

observeEvent(input$file1, handlerExpr = { output$volcanoplot1 <- renderPlotly({ volcanoplot <- plot_ly( data = track2_data1(), type = "scatter", colors = NULL, alpha = NULL, x = track2_data1()$beta, y = -log10(track2_data1()$Pvalue), text = track2_data1()$outcome_name, mode = "markers" ) %>% layout(xaxis = list(title = "effect_estimate"), yaxis = list(title = "-log10(p-value)")) }) })

>> Track 2 ====

Define conditional element to show main panel only when file(s) uploaded

output$file_imported2 <- reactive({ return(!is.null(input$file2)) })

outputOptions(output, "file_imported2", suspendWhenHidden = FALSE)

Create data to describe the imported dataset

output$rowcount2 <- renderText(paste("Total number of rows in uploaded file(s):", nrow(track3_data1()))) output$colcount2 <- renderText(paste("Total number of columns in uploaded file(s):", ncol(track3_data1())))

Render head of imported dataset

output$data2 <- renderTable({ track3_data1() %>% head })

Render volcano plot

observeEvent(input$file2, handlerExpr = { output$volcanoplot2 <- renderPlotly({ volcanoplot <- plot_ly( data = track3_data1(), type = "scatter", colors = NULL, alpha = NULL, x = track3_data1()$beta, y = -log10(track3_data1()$Pvalue), text = track3_data1()$outcome_name, mode = "markers" ) %>% layout(xaxis = list(title = "effect_estimate"), yaxis = list(title = "-log10(p-value)")) }) })

>> Track 3 ====

Define conditional element to show main panel only when file(s) uploaded

output$file_imported3 <- reactive({ return(!is.null(input$file3)) })

outputOptions(output, "file_imported3", suspendWhenHidden = FALSE)

Create data to describe the imported dataset

output$rowcount3 <- renderText(paste("Total number of rows in uploaded file(s):", nrow(track4_data1()))) output$colcount3 <- renderText(paste("Total number of columns in uploaded file(s):", ncol(track4_data1())))

Render head of imported dataset

output$data3 <- renderTable({ track4_data1() %>% head })

Render volcano plot

observeEvent(input$file3, handlerExpr = { output$volcanoplot3 <- renderPlotly({ volcanoplot <- plot_ly( data = track4_data1(), type = "scatter", colors = NULL, alpha = NULL, x = track4_data1()$beta, y = -log10(track4_data1()$Pvalue), text = track4_data1()$outcome_name, mode = "markers" ) %>% layout(xaxis = list(title = "effect_estimate"), yaxis = list(title = "-log10(p-value)")) }) })

CIRCOS PARAMETERS ====

> sidebar panel ====

output$pval <- renderText(paste0("New threshold: 0.05/", input$pvalue_adjustment, " = ", round(0.05/input$pvalue_adjustment, digits = 8)) ) output$pval_label <- renderText(paste0("P > 0.05/", input$pvalue_adjustment))

When the first file is uploaded, pass the column headings to the selectInput widgets

observeEvent(input$file1, { updateSelectInput(session, "label_column", choices = c("",colnames(track2_data1())))

updateSelectInput(session,
                  "section_column",
                  choices = c("",colnames(track2_data1())))

updateSelectInput(session,
                  "estimate_column",
                  choices = c("",colnames(track2_data1())))

updateSelectInput(session,
                  "pvalue_column",
                  choices = c("",colnames(track2_data1())))

updateSelectInput(session,
                  "confidence_interval_lower_column",
                  choices = c("",colnames(track2_data1())))

updateSelectInput(session,
                  "confidence_interval_upper_column",
                  choices = c("",colnames(track2_data1())))

} )

Because the my_circos_plot() function expects a column number rather than name,

which is what the selectInput widgets return, use the following functions to convert the

column name into the column number

label_column_number <- reactive({which(colnames(track2_data1())==input$label_column)}) section_column_number <- reactive({which(colnames(track2_data1())==input$section_column)}) estimate_column_number <- reactive({which(colnames(track2_data1())==input$estimate_column)}) pvalue_column_number <- reactive({which(colnames(track2_data1())==input$pvalue_column)}) confidence_interval_lower_column_number <- reactive({which(colnames(track2_data1())==input$confidence_interval_lower_column)}) confidence_interval_upper_column_number <- reactive({which(colnames(track2_data1())==input$confidence_interval_upper_column)})

output$pdf <- renderUI({ if(file.exists(outfile)){ tags$iframe(src=outfile,style="height:600px; width:100%")} })

outfile <- tempfile("myfile", fileext = ".pdf", tmpdir ="www")

observeEvent(input$circosbutton, handlerExpr = { output$pdf <- renderUI({ pdf(outfile, width = 35, height = 35, pointsize = 30) isolate({ my_circos_plot( track_number = input$track_number, track2_data1 = track2_data1(), track3_data1 = track3_data1(), track4_data1 = track4_data1(), section_column = section_column_number(), # This returns the column number, as defined above. label_column = label_column_number(), estimate_column = estimate_column_number(), pvalue_column = pvalue_column_number(), pvalue_adjustment = (0.05/input$pvalue_adjustment), confidence_interval_lower_column = confidence_interval_lower_column_number(), confidence_interval_upper_column = confidence_interval_upper_column_number(), legend = input$legend, track2_label = input$track2_label, track3_label = input$track3_label, track4_label = input$track4_label, pvalue_label = input$pvalue_label) })

               dev.off()
               if(file.exists(outfile)){
                 tags$iframe(src=str_sub(outfile,5),style="height:800px; width:100%")}
             })
           })

Return a list containing the filename

onStop(function() { unlink(outfile, recursive = TRUE) })

> main panel ====

Keep shiny app awake ====

output$keepAlive <- renderText({ req(input$count) paste("keep alive ", input$count) })

})

------------------------------------------------------------------------------

shinyApp(ui = ui, server = server)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/andrewsali/shinycssloaders/issues/41?email_source=notifications&email_token=AAHIQFBJFVPYO45QPORY52LQ72YEHA5CNFSM4KLX4HA2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJ67LXY#issuecomment-578680287, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHIQFC5MYRFCC7RABRQAATQ72YEHANCNFSM4KLX4HAQ .

daattali commented 4 years ago

Version 9565546494f3395a257546312313929ec0bbf968 works for you but the CRAN version doesn't? That's extremely strange because there are no difference in the code between the two. The only difference between the two versions is in the README and metadata, but the code is identical. I would really need a reproducible example to troubleshoot this.

DomnechFinney commented 4 years ago

I also have an issue with new update, where spinner would not show using chrome but it would in IE.

I tried mattlee821 suggestion: remotes::install_github("andrewsali/shinycssloaders", ref="8779ff0f0ad32b0731c06067e35fa65d85f66a89")

and suprisingly it fixed it. Maybe its a browser compatibility issue.

daattali commented 4 years ago

Does installing the latest github version fix it, because the latest github version fixed another similar issue? If not, can you post a minimal reproducible example please?

DomnechFinney commented 4 years ago

I figured out my issue. I updated shinycssloaders from 0.2 to 0.3 but didnt restart my RStudio session. When I ran remotes::install_github("andrewsali/shinycssloaders", ref="8779ff0f0ad32b0731c06067e35fa65d85f66a89") it was downgrading to back to 0.2, and then it would work. :/ So now my 0.3 version is working perfectly. Thanks

daattali commented 4 years ago

@ismirsehregal @mattlee821 did you have any reproducible examples showing the problem?

daattali commented 4 years ago

I would really appreciate if one of you could show me some code that breaks with the new version. Otherwise I'll consider this fixed

ismirsehregal commented 4 years ago

@daattali today I took some more time to search for the issue and finally found what is causing the problem for me.

If I source the following example with the latest github version of shinycssloaders the spinner is hidden right from the beginning.

library(shiny)
library(shinycssloaders)

ui <- fluidPage(
  withSpinner(uiOutput("dummyid"))
)

server = function(input, output, session){}

app <- shinyApp(ui, server)
runApp(app, host ="0.0.0.0", port = 80, launch.browser = TRUE) # causes hidden spinner

screen The same code works as expected in version 0.2.0. Commenting out the last line using runApp and running app directly fixes the issue for the dev-version.

daattali commented 4 years ago

That's very strange. When I run your code, I do see the spinner. If you add an output$dummyid to the server, it still doesn't work? What browser+OS are you on?

ismirsehregal commented 4 years ago

I'll check. This is on Windows 10 7 + Chrome.

ismirsehregal commented 4 years ago

Using this:

library(shiny)
library(shinycssloaders)

ui <- fluidPage(
  withSpinner(uiOutput("dummyid"))
)

server = function(input, output, session){
  output$dummyid <- renderUI({
    Sys.sleep(5)
    "result"
  })
}

app <- shinyApp(ui, server)
runApp(app, host ="0.0.0.0", port = 80, launch.browser = TRUE) # causes hidden spinner

Its the same effect:

screen

daattali commented 4 years ago

So you're saying that for you running runApp() always breaks shinycssloaders? Can you open a separate issue for this? This issue is "withSpinner() removes reactive element of uploading data and selecting column names" and I don't think you're seeing that behaviour. Can I close this issue?

ismirsehregal commented 4 years ago

Sure, no problem.

withSpinner() removes reactive element of uploading data and selecting column names

I saw that behaviour with the latest cran version - but this is indeed fixed with the latest dev version for me, but this problem was still left.

ismirsehregal commented 4 years ago

Sorry, it's windows 7 and I just tried the same on a windows 10 system and can't reproduce the same behaviour. Seems to be related with using port 80 - here is the new issue.

mattlee821 commented 4 years ago

I would really appreciate if one of you could show me some code that breaks with the new version. Otherwise I'll consider this fixed

Sorry - i've tried to find a minimal reproducible example of this but it seems to work each time. I'm okay with closing the issue as the fix here (and the fact no code has changes) is stable and as I can't reproduce it I'm going to assume theres an issue elsewhere in my apps cod:

Version 9565546494f3395a257546312313929ec0bbf968 works for you but the CRAN version doesn't? That's extremely strange because there are no difference in the code between the two. The only difference between the two versions is in the README and metadata, but the code is identical. I would really need a reproducible example to troubleshoot this.