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

uiOutput not working with shinycssloaders 0.3 #39

Closed trvinh closed 4 years ago

trvinh commented 4 years ago

Hi, today I installed the tool PhyloProfile (from Bioconductor) and updated all of its dependencies including the shinycssloaders. Suddenly that tool worked incorrectly, some of the uiOutput elements couldn't be rendered and it showed no error messages, they are just empty. When I downgrade shinycssloaders back to version 0.2.0, it worked again. Have you ever encountered the same issue like that, or does the new version have some conflicts with other libraries? I am attaching here the sessionInfo if it can help

> sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS  10.15.2

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
 [1] grid      stats4    parallel  stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] PhyloProfile_1.0.3     ExperimentHub_1.12.0   AnnotationHub_2.18.0   BiocFileCache_1.10.2  
 [5] dbplyr_1.4.2           zoo_1.8-7              OmaDB_2.2.0            plyr_1.8.5            
 [9] httr_1.4.1             shinyjs_1.1            shinyBS_0.61           RColorBrewer_1.1-2    
[13] gridExtra_2.3          GO.db_3.10.0           AnnotationDbi_1.48.0   ggplot2_3.2.1         
[17] GenomeInfoDbData_1.2.2 energy_1.7-7           data.table_1.12.8      colourpicker_1.0      
[21] Biostrings_2.54.0      XVector_0.26.0         IRanges_2.20.2         S4Vectors_0.24.3      
[25] bioDist_1.58.0         KernSmooth_2.23-16     Biobase_2.46.0         BiocGenerics_0.32.0   
[29] ape_5.3                shiny_1.4.0           

loaded via a namespace (and not attached):
 [1] nlme_3.1-143                  bitops_1.0-6                  matrixStats_0.55.0           
 [4] bit64_0.9-7                   GenomeInfoDb_1.22.0           tools_3.6.0                  
 [7] backports_1.1.5               R6_2.4.1                      DT_0.11                      
[10] DBI_1.1.0                     lazyeval_0.2.2                colorspace_1.4-1             
[13] withr_2.1.2                   tidyselect_0.2.5              bit_1.1-15.1                 
[16] curl_4.3                      compiler_3.6.0                graph_1.64.0                 
[19] SparseM_1.78                  xml2_1.2.2                    topGO_2.38.1                 
[22] scales_1.1.0                  rappdirs_0.3.1                digest_0.6.23                
[25] rmarkdown_2.0                 pkgconfig_2.0.3               htmltools_0.4.0              
[28] fastmap_1.0.1                 htmlwidgets_1.5.1             rlang_0.4.2                  
[31] rstudioapi_0.10               RSQLite_2.2.0                 jsonlite_1.6                 
[34] crosstalk_1.0.0               dplyr_0.8.3                   RCurl_1.98-1.1               
[37] magrittr_1.5                  Rcpp_1.0.3                    munsell_0.5.0                
[40] shinycssloaders_0.2.0         lifecycle_0.1.0               yaml_2.2.0                   
[43] zlibbioc_1.32.0               blob_1.2.0                    promises_1.1.0               
[46] crayon_1.3.4                  miniUI_0.1.1.1                lattice_0.20-38              
[49] knitr_1.27                    zeallot_0.1.0                 pillar_1.4.3                 
[52] GenomicRanges_1.38.0          boot_1.3-24                   glue_1.3.1                   
[55] BiocVersion_3.10.1            evaluate_0.14                 BiocManager_1.30.10          
[58] vctrs_0.2.1                   httpuv_1.5.2                  gtable_0.3.0                 
[61] purrr_0.3.3                   assertthat_0.2.1              xfun_0.12                    
[64] mime_0.8                      xtable_1.8-4                  later_1.0.0                  
[67] rsconnect_0.8.16              tibble_2.1.3                  memoise_1.1.0                
[70] interactiveDisplayBase_1.24.0 BiocStyle_2.14.4  

With the shinycssloaders v0.2.0 I got this (please notice the fileInput Upload input file and the two 1st variable and 2nd variable, they was rendered within a uiOutput)

image

With the v0.3.0, it became

image

Many thanks! Vinh

daattali commented 4 years ago

Could you produce a minimal reproducible example? I just tried a very simple uiOutput with shinycssloaders and it worked fine.

trvinh commented 4 years ago

I also tried with small examples, it worked perfectly. I removed shinycssloaders out of PhyloProfile and the tool also worked again. I think shinycssloaders has some conflicts with any other dependencies in PhyloProfile, but I couldn't figure out which one :-(

I will keep trying to reproduce the issue independently from PhyloProfile. One thing I can confirm currently is that, rendering other shiny elements works just fine with shinycssloaders loaded, as long as they are not put inside a uiOutput. And it is not necessary that any functions of shinycssloaders are applied on that element, like the fileInput and textInput objects above, the code for one of them is only like this:

output$var1ID.ui <- renderUI({
        longDataframe <- getMainInput()
        if (is.null(longDataframe)) {
            textInput(
                "var1ID",
                h5("1st variable:"),
                value = "Variable 1",
                width = "100%",
                placeholder = "Name of first variable"
            )
        } else {
            textInput(
                "var1ID", h5("1st variable:"),
                value = colnames(longDataframe)[4],
                width = "100%",
                placeholder = "Name of first variable"
            )
        }
    })

If you found something, please let me know. Thanks again!

trvinh commented 4 years ago

Hi Dean, I think I found the issue, and I think it was because of the conditionalPanel, not the uiOutput. Could you please take a look at this example:

library(shiny)
library(shinycssloaders)

ui <- fluidPage(
    sidebarLayout(
        sidebarPanel(
            selectInput(
                "select",
                label = h5("Select:"),
                choices = list(
                    "Max" = "max",
                    "Min" = "min",
                    "None" = "none"
                ),
                selected = "min",
                width = 130
            ),
            br(),

            conditionalPanel(
                condition = "output.selectStatus == 1",
                strong(h5("You have selected:")),
                shinycssloaders::withSpinner(
                    uiOutput("choice")
                )
            )
        ),

        mainPanel(
            strong("Something wrong!"),
            h5("The conditional panel works not as expected when using shinycssloaders."),
        )
    )
)

server <- function(input, output, session) {
    output$selectStatus <- reactive({
        if (input$select == "none") {
            return(0)
        } else return(1)
    })
    outputOptions(output, "selectStatus", suspendWhenHidden = FALSE)

    output$choice <- renderUI({
        em(input$select)
    })
}
shinyApp(ui, server)

You will see that the uiOutput choice does not work correctly as expected. Remove the withSpinner() function, it works normally.

daattali commented 4 years ago

Can you clarify the exact behaviour that's expected and what you see instead? I tried running this and I'm not sure what issue I'm supposed to be seeing.

This piece of code is also quite long and involves many moving pieces, it'd help if it was cut short to only include the essential parts

Thanks

trvinh commented 4 years ago

Hi Dean,

I hope this example is clearer.

This code worked:

library(shiny)
library(shinycssloaders)

ui <- fluidPage(
    selectInput(
        "select",
        label = h5("Please turn the light:"),
        choices = list("On" = "on", "Off" = "off")
    ),

    conditionalPanel(
        condition = "output.selectStatus == 1",
        # shinycssloaders::withSpinner(
            uiOutput("choice")
        # )
    )
)

server <- function(input, output, session) {
    output$selectStatus <- reactive({
        if (input$select == "off") {
            return(0)
        } else return(1)
    })
    outputOptions(output, "selectStatus", suspendWhenHidden = FALSE)

    output$choice <- renderUI({
        paste("The light is turned ", input$select)
    })
}
shinyApp(ui, server)

With that code I would like to print the message "The light is turned on" if I select the option on:

image

and show nothing if I select off:

image

If I uncomment the shinycsloaders::withSpinner, it will not work anymore, the message is always empty.

P.S.: this version works also:

library(shiny)
library(shinycssloaders)

ui <- fluidPage(
    selectInput(
        "select",
        label = h5("Please turn the light:"),
        choices = list("On" = "on", "Off" = "off")
    ),

    conditionalPanel(
        condition = "input.select == 'on'",
        shinycssloaders::withSpinner(
            uiOutput("choice")
        )
    )
)

server <- function(input, output, session) {
    output$choice <- renderUI({
        paste("The light is turned ", input$select)
    })
}
shinyApp(ui, server)

but with this I cannot use an output variable as the condition for the conditionalPanel

lbusett commented 4 years ago

Hi. I am seeing the same problem: apparently, these "kind" of calls have problems on v0.3.0

shiny::conditionalPanel(
  condition = "output.pcolt_onview", {
      shinycssloaders::withSpinner(
        leaflet::leafletOutput("pcolt_map_view", width = "95%")
      )
   })

Inspecting the browser reveals these kind of errors, both in the example by @trvinh and in my app:

image

image

HTH!

daattali commented 4 years ago

Thanks for the information. I'm currently traveling and unable to troubleshoot, but your screenshot does provide some hints.

It looks like this is likely caused by https://github.com/andrewsali/shinycssloaders/pull/27 - and now that I look at that thread, it does seem like @keqiang has reported this same issue.

To verify 100% that this is the cause, could you try installing the package from github both before and after that change? So try doing remotes::install_github("andrewsali/shinycssloaders", ref="8779ff0f0ad32b0731c06067e35fa65d85f66a89") and see if the problem goes away (this was the commit before introducing the pull request) and then try remotes::install_github("andrewsali/shinycssloaders", ref="9565546494f3395a257546312313929ec0bbf968") and see if the problem re-appears.

@merlinoa do you think you might have an idea what the issue here is? I'm not familiar with this javascript code

lbusett commented 4 years ago

I can confirm that rolling back to before #27 removes the issue. Also, I tested this open PR by @bthieurmel https://github.com/andrewsali/shinycssloaders/pull/31 and it seems to solve it.

ismirsehregal commented 4 years ago

Just FYI, there are others with similar problems: https://stackoverflow.com/questions/59895418/why-conditionalpanel-does-not-work-on-first-attempt

daattali commented 4 years ago

@lbusett @ismirsehregal @lbusett I just submitted a commit that I hope fixed this. Could you please install the latest github version and let me know?

trvinh commented 4 years ago

@daattali it works for me 👍

ismirsehregal commented 4 years ago

@daattali Thanks for your effort! Unfortunately in my app of concern I'm still unable to display a spinner. They are right away started with classes "load-container load1 shiny-spinner-hidden". I'd love to share a minimal example but so far wasn't able to generate one showing the issue.

lbusett commented 4 years ago

@daattali All seems good also on my side. Thanks for the quick fix!

daattali commented 4 years ago

@ismirsehregal it'd be very helpful if you keep trying and show me a minimal example!

ismirsehregal commented 4 years ago

@daattali sorry, still no luck. But I don't want to block your development here. I'll let you know when I found the issue.

daattali commented 4 years ago

Feel free to open an issue when you can reproduce

daattali commented 4 years ago

@ismirsehregal I plan on releasing to CRAN soon, so if you are able to reproduce a bug please let me know

lbusett commented 4 years ago

Hi @daattali ,

I was just wondering if you are still planning for a new CRAN release soon(ish) to fix this: that way I could avoid depending from the github repo for a couple of Shiny apps I am mantaining.

thanks in advance,

Lorenzo

PS: Let me know if I can halp in any way, in case.

daattali commented 4 years ago

I'll put it in my calendar to submit next week if I don't hear about any more regression bugs. When I submitted the current version to CRAN, it was stable for over a year in GitHub and nobody had any issues opened, and a week after it went to CRAN I received a ton of issues, so I'm trying to be careful not to repeat that :)

daattali commented 4 years ago

@ismirsehregal please let us know if you still experience issues

ismirsehregal commented 4 years ago

@daattali nothing to add from my side, I think the current version can be submitted. Thanks again for your great work! Cheers

ismirsehregal commented 4 years ago

Out of curiosity: Was there any other blocking issue? Or just a lack of time?

daattali commented 4 years ago

The latter, sort of. I try not to release multiple packages in succession to not overwhelm myself with new bug reports and I just had too many other packages recently getting updated

daattali commented 4 years ago

By the way, you can use https://cranalerts.com/ if you want to get notified when it hits CRAN