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
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:
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