Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shiny progress bars not working properly with networkD3 #250

Closed
ghost opened this issue Feb 15, 2019 · 6 comments
Closed

Shiny progress bars not working properly with networkD3 #250

ghost opened this issue Feb 15, 2019 · 6 comments

Comments

@ghost
Copy link

ghost commented Feb 15, 2019

Hi,
I have some issues with progress bars in Shiny and the package networkD3. If I try to use a progress bar and the networkD3 package, the bar shows up once but not in subsequent calls. But each time the slider is used the progess bar should appear, which is the case without the sankey diagram.
I tested in Chrome.
Here is a minimum example code:

require(shinyjs)
require(shiny)
require(networkD3)
require(jsonlite)
require(shinydashboard)

ui <- function(){
  fluidPage(
    fluidRow(
      column(width = 12, style = "margin: 0px; padding: 0px;",
             box(title = "Flow Diagram", status = "primary", solidHeader = F, width = 7,
                 sankeyNetworkOutput("sankeyFlow", width = "100%", height = "500px")
             )
      ), 
      sliderInput("numLanes", label = "Number of Top Lanes", min = 0, max = 30, value = 10)
    )
  )
}

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

  observeEvent(c(input$numLanes), {
    withProgress(message = "Wait...", value = NULL, {
      Sys.sleep(1.0)
    })
  })

  output$sankeyFlow <- renderSankeyNetwork({
    print("sankey")

    withProgress(message = "Updating flow diagram...", value = NULL, {

      # Load energy projection data
      URL <- "https://cdn.rawgit.com/christophergandrud/networkD3/master/JSONdata/energy.json"
      Energy <- jsonlite::fromJSON(URL)

      nLanes <- input$numLanes

      plot <- sankeyNetwork(Links = Energy$links, Nodes = Energy$nodes, Source = "source",
                                  Target = "target", Value = "value", NodeID = "name",
                                  units = "TWh", fontSize = 12, nodeWidth = 30)
      return(plot)
    })
  })
}

shinyApp(ui = ui, server = server)

In my use case I use several progress bars and none are displayed if I include the flow diagram. I do not think it is a Shiny issue as it only occurs with this package.
Thanks, Christian

@cjyetman
Copy link
Collaborator

Using your example, if I drag the slider around slowly but continually (presumably causing a series of redraws) I do see the progress notifications, which makes me think that the progress notification code must have some kind of timer that only shows the notification when it thinks the process is going to or is taking long enough to warrant the notification. But honestly, I don't know anything about that code... maybe you should ask the shiny developers?

@ghost
Copy link
Author

ghost commented Feb 15, 2019

Ok thanks for looking at it. I will cross post as a shiny issue. There is an explicit timer in the progress bar, so it should always render as it is big enough even if it has some timer implemented that only renders on long delays.

@cjyetman
Copy link
Collaborator

after some experimentation, I'm pretty sure this is caused by the same issue in #214

there's a PR #215 that would probably fix this, but it hasn't been merged yet

@cjyetman
Copy link
Collaborator

issue in Shiny repo is here rstudio/shiny#2329

@cjyetman
Copy link
Collaborator

Looks like this is/will be finally fixed upstream with rstudio/shiny@3d11780

will close this issue once I have verified it

@cjyetman cjyetman added the bug label Apr 10, 2019
@cjyetman
Copy link
Collaborator

This issue has been resolved with the dev version of shiny and should be released on CRAN soon as shiny v1.3.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant