Progress bars doesn't show with networkD3 package

Hi,
I have some issues with progress bars in Shiny and the package networkD3. The progress bar shows up fine without trying to render a diagram from that package. If try to use a progress bar and the networkD3 package, the bar shows up once but not in subsequent calls. 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)

Maybe someone has some insight on why this is happening and a possible workaround. In my use case I use several progress bars and none are displayed if I include the flow diagram.

Thanks, Christian

I just get ERROR: plot.new has not been called yet when I run your example.

I forgot to include a package, shinydashboard. I edited the example code. It should work now, well show the error properly :smiley:

I'm pretty sure this is a conflict/bug with how networkD3 enables tooltips with multiple lines in sankeyNetwork().

see...

and there's a PR with a potential fix for it, but it hasn't been merged yet...

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.