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

The spinner keeps spinning when rendering a table with the same data #10

Closed greenTea2Codes closed 6 years ago

greenTea2Codes commented 6 years ago

Hi I am new to R and shiny. I use the spinner like below: in the UI block: withSpinner(tableOutput("freq_table"))

in the Server block: observeEvent(input$button, { df_log <<- update(input$dateRange[1], input$dateRange[2]) }) output$freq_table <- renderTable({ input$button df_freq_table <- as.data.frame(table(df_log$user_id)) colnames(df_df_freq_table) <- c("user_id", "count") df_freq_table <- df_freq_table[order(-df_freq_table$count, df_freq_table$user_id),] df_freq_table })

When the date range changes, the table is rendered. But if the date range is the same, the spinner just keep spinning. The table renders if I remove the spinner. Could someone tell me why the spinner keeps spinning if the data is the same? Is there a way to tell the spinner that the table is updated even though the data set is the same? Thank you

andrewsali commented 6 years ago

If you are not using the latest github version (updated a few days ago), could you try to see if installing that resolves the issue?

Otherwise we will need a complete reproducible example to be able to dig into what might be the exact problem in this case.

On Mon, Dec 4, 2017, 21:32 greenTea2Codes notifications@github.com wrote:

Hi I am new to R and shiny. I use the spinner like below: in the UI block: withSpinner(tableOutput("freq_table"))

in the Server block: observeEvent(input$button, { df_log <<- update(input$dateRange[1], input$dateRange[2]) }) output$freq_table <- renderTable({ input$button df_freq_table <- as.data.frame(table(df_log$user_id)) colnames(df_df_freq_table) <- c("user_id", "count") df_freq_table <- df_freq_table[order(-df_freq_table$count, df_freq_table$user_id),] df_freq_table })

When the date range changes, the table is rendered. But if the date range is the same, the spinner just keep spinning. The table renders if I remove the spinner. Could someone tell me why the spinner keeps spinning if the data is the same? Is there a way to tell the spinner that the table is updated even though the data set is the same? Thank you

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/andrewsali/shinycssloaders/issues/10, or mute the thread https://github.com/notifications/unsubscribe-auth/AOYYp9TBYe9AouL6DWqNwqAf7-ooHV7pks5s9FbbgaJpZM4Q1RXY .

greenTea2Codes commented 6 years ago

Hi, I have been using v.0.2.0 from CRAN. I tried devtools::install_github('andrewsali/shinycssloaders') in the R studio console but when I did packageVersion("shinycssloaders") I still got v. 0.2.0. Could you advise me how to get your latest version? Kind regards

andrewsali commented 6 years ago

That's the right way, just restart your R session and load the library again and it should be the new one.

You can check the exact version using devtools::session_info()

On Tue, Dec 5, 2017, 09:50 greenTea2Codes notifications@github.com wrote:

Hi, I have been using v.0.2.0 from CRAN. I tried devtools::install_github('andrewsali/shinycssloaders') in the R studio console but when I did packageVersion("shinycssloaders") I still got v. 0.2.0. Could you advise me how to get your latest version? Kind regards

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/andrewsali/shinycssloaders/issues/10#issuecomment-349236704, or mute the thread https://github.com/notifications/unsubscribe-auth/AOYYp7LudLq-JlHeheI828nyihUJ1BCsks5s9QPtgaJpZM4Q1RXY .

greenTea2Codes commented 6 years ago

Hi, After I ran my app in the R studio and did devtools::session_info() I got chinycssloaders *0.2.0 2017-12-05 Github (andrewsali/shinycssloaders@8779ff0) Does it mean I am still using v.0.2.0? Should I re-install or update the package?

Also, I ran the app and the issue persists.

andrewsali commented 6 years ago

That looks correct, it's the latest version - do you still experience the issue? Also, before (the first time you experienced the problem) you were using the CRAN version?

If the answer to both questions is yes, then we will need a complete (runnable) reproducible example to be able to investigate.

On Tue, Dec 5, 2017, 11:46 greenTea2Codes notifications@github.com wrote:

Hi, After I ran my app in the R studio and did devtools::session_info() I got chinycssloaders *0.2.0 2017-12-05 Github (8779ff0 https://github.com/andrewsali/shinycssloaders/commit/8779ff0) Does it mean I am still using v.0.2.0? Should I re-install or update the package?

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/andrewsali/shinycssloaders/issues/10#issuecomment-349266943, or mute the thread https://github.com/notifications/unsubscribe-auth/AOYYp4iaJCtdcQu09-0piZvQ9olZmo2Xks5s9R8bgaJpZM4Q1RXY .

greenTea2Codes commented 6 years ago

Yes to both of your questions. I am afraid that I cannot post the complete scripts here - one way I could do is to simplify the codes and reproduce the issue in a new project. I wish I would have time later for further study.

At the moment, I removed the spinners from tableOutputs and the tables render as expected even if the dataset is the same. It works fine for the plotOutputs though, which puzzles me. I will post more if I learn more from the issue.

Thank you for your replies.

andrewsali commented 6 years ago

If you could contribute a reproducible issue, that would be highly appreciated. I will keep the issue open for 2 weeks, if you can provide an example by then that would be great. Otherwise after I will close the issue due to lack of reproducibility.

andrewsali commented 6 years ago

Closing as there is no reproducible example.

alexturcan commented 6 years ago

I've been experiencing the same issue. Given a table and a plot output each with a spinner, the first time around they both complete successfully, but any subsequent rendering completes only for the plot, while the table spinner persists.

Here is a reproducible example:

library(shiny)
library(shinycssloaders)

ui <- fluidPage(
  actionButton("execute", "Execute"),
  withSpinner(plotOutput("plot")),
  withSpinner(tableOutput("table"))
)

server <- function(input, output) {

  our_data <- reactive({
    input$execute

    data.frame(n = seq(0,100,5))
  })

  output$plot <- renderPlot({
    hist(our_data()$n)
  })

  output$table <- renderTable({
    our_data()
  })
}

shinyApp(ui, server)
andrewsali commented 6 years ago

Thanks for the reproducible example. The issue seems to be that shiny:value event is not triggered when the same data is received for the table, even though the client seems to be sending the data. I'll reach out to Shiny team to understand if this is really what they intended.

alexturcan commented 6 years ago

Hi Andrew, I was wondering if there's been any progress on this issue? Thank you.

andrewsali commented 6 years ago

Apologies for the delay, I was a bit under water. Opened an issue in the shiny github repo, it seems an issue on their end.

AkshataSalian commented 6 years ago

Hi Andrew, I am also facing this issue. Any update so far on this?

andrewsali commented 6 years ago

I have proposed a fix for Shiny, it will probably be integrated soon into their master branch. Until that happens, you can install my fix that should resolve the problem via:

devtools::install_github("andrewsali/shiny")
AkshataSalian commented 6 years ago

Thank you so much, Andrew!!

andrewsali commented 6 years ago

The fix has now been incorporated into rstudio/shiny in github.

dylancis commented 6 years ago

We just need to update shiny to have it fixed or is there any code change required here ? Thanks.

andrewsali commented 6 years ago

No code change required, just install shiny from github via:

devtools::install_github("rstudio/shiny")

lizigarland96 commented 4 years ago

Is this version of shiny updated in CRAN?

daattali commented 4 years ago

The current cran version is from 3 months ago. If something is failing for you, please test using this version: devtools::install_github('daattali/shinycssloaders')

lizigarland96 commented 4 years ago

I am unable to test with that version due to "port 443: Bad Access"

daattali commented 4 years ago

That doesnt look like a shinycssloaders issue. Try

Any combination of the above, preferably all of them. But that's definitely not an issue of this package

lizigarland96 commented 4 years ago

I am unable to install version: devtools::install_github('daattali/shinycssloaders') due to a corporate wall. But I am still experiencing spinning issues with tableOutput, using Shiny version 1.4.0.2 and shinycssloaders 0.3 under R version 3.6.0

daattali commented 4 years ago

If you believe there's a bug in the package, please send a minimal reproducible code sample

On Tue., Apr. 28, 2020, 12:33 lizigarland96, notifications@github.com wrote:

I am unable to install version: devtools::install_github('daattali/shinycssloaders') due to a corporate wall. But I am still experiencing spinning issues with tableOutput, using Shiny version 1.4.0.2 and shinycssloaders 0.3 under R version 3.6.0

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/daattali/shinycssloaders/issues/10#issuecomment-620718233, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHIQFCEZZNGQDUONF6I6MDRO4ANTANCNFSM4EGVCXMA .

aavanesy commented 4 years ago

Hi, I have the same issue. Reinstalled shiny and installed the package from github. Spinner keeps running if the rendered object is unchanged.

daattali commented 4 years ago

If you believe there's a bug, please include a small reproducible sample code so I can see it and troubleshoot.

taustring commented 3 years ago

@daattali I have a similar issue where I have included an actionButton to download data from the web to cache locally and use when offline but withSpinner active on the button, it spins from loading the app without any user input when it should only be active while the data pull is processing, and also prevents clicking the button.

I reproduced the issue with the sample app, I just turned the button in to a reset button to restore the original value of the slider. The function of the button isn't the same as my application, but it is behaving the same. The button works as it should if the spinner is removed, but the button isn't clickable with the spinner active since it is constantly "refreshing."

library(shiny)
library(shinyjs)
library(shinycssloaders)

ui <- fluidPage(

    shinyjs::useShinyjs(),

    sidebarLayout(
        sidebarPanel(
            sliderInput("bins",
                        "Number of bins:",
                        min = 1,
                        max = 50,
                        value = 30),

            actionButton(inputId = "refresh", label = "Refresh Cache") 
                %>% withSpinner(type = 4, color = "blue", size = 1, hide.ui = FALSE)
            ),

        mainPanel(
           plotOutput("distPlot")
        )
    )
)

server <- function(input, output) {

    observeEvent(input$refresh, {
        shinyjs::reset("bins")
    })

    output$distPlot <- renderPlot({
        x    <- faithful[, 2]
        bins <- seq(min(x), max(x), length.out = input$bins + 1)
        hist(x, breaks = bins, col = 'darkgray', border = 'white')
    })
}

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

shinycssloaders works for outputs specifically. Action buttons are inputs, not outputs. This package does not work with buttons

taustring commented 3 years ago

@daattali thanks for the clarification, modified my google search and realized that it's an easy solution, just not as pretty as a spinner.


observeEvent(input$refresh, {
        showModal(modalDialog("Downloading Data..."))
        #data pulls 
        removeModal()
})
daattali commented 3 years ago

Yeah, you can use shinyalert if you want it to look a little bit prettier, but anything other than shinycssloaders wil lrequire you to manually decide when to show/hide