1

I am developing a Shiny application which has two components Sankey Diagram and one action button which pop up "SaveMsg" dialog box on click of button .

I am seeing unexpected behavior where, If I user actionbutton and Sankeyvisualization in one dashboard, on click of action button, dashboard screen greyed out.

however If I comment Sankey code and keep only Action button on UI, Action button works as expected by showing pop up message of "save successfull". If I comment action button code and keep only Sankey code in UI, I am able to see sankey output on dashboard.

Sankey code and action button both are working as expected separately, however if I place both in one dashboard action button greyed outscreen dashboard screen.

I have also attached sample code-

library(shiny)
library(networkD3)
library(shinydashboard)
value <-  c(12,21,41,12,81)
source <- c(4,1,5,2,1)
target <- c(0,0,1,3,3)
edges2 <- data.frame(cbind(value,source,target))

names(edges2) <- c("value","source","target")
indx  <- c(0,1,2,3,4,5)
ID    <- c('CITY_1','CITY_2','CITY_3','CITY_4','CITY_5','CITY_6')
nodes <-data.frame(cbind(ID,indx))

ui <- dashboardPage(
  dashboardHeader(
  ),
  dashboardSidebar(disable = TRUE),
  dashboardBody(
    fluidPage(
      actionLink("savebtn", "Save button")
      ,sankeyNetworkOutput("simple")
    )
  )
)

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

  # Show modal when button is clicked.
  observeEvent(input$savebtn, {
    showModal(modalDialog(
      title = "Save successful"))
  })

  output$simple <- renderSankeyNetwork({
    sankeyNetwork(Links = edges2, Nodes = nodes,
                  Source = "source", Target = "target",
                  Value = "value",  NodeID = "ID" 
                  ,units = "SSN" )
  })
}

shinyApp(ui = ui, server = server)
CJ Yetman
  • 8,373
  • 2
  • 24
  • 56
  • Can you provide a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)? – Samuel Sep 16 '17 at 13:29
  • Hi Samuel, I have updated complete reproducible code, on click of save of button dashboard grayed out, however both action button and sankeyNetworkoutput show output separately when other is commented in UI. – Sourabh Kumar Sep 16 '17 at 15:33
  • the error does not depend on your specific sankey network, so you could just use a simple network from the help pages of sankeyNetwork... – shosaco Sep 16 '17 at 15:35
  • Hi shosaco, Thanks for prompt response, I have updated code in description section with simplest sankeyNetwork code copied from help pages. However still On click of actionbutton, dashboard grayed out. – Sourabh Kumar Sep 16 '17 at 15:59
  • Can someone please check and share information why action button is not working with SankeyNetwork and what is workaround to pop up on click of button – Sourabh Kumar Sep 17 '17 at 10:06

2 Answers2

1

I haven't dug into the problem so I'm not sure why that's happening. But in case the modal you want to show is just some text (doesn't contain shiny elements), you can use shinyalert which also does modals (not on CRAN yet, haven't published it yet). Here's your code using shinyalert. Hope that helps

library(shiny)
library(networkD3)
library(shinyalert)
value <-  c(12,21,41,12,81)
source <- c(4,1,5,2,1)
target <- c(0,0,1,3,3)
edges2 <- data.frame(cbind(value,source,target))

names(edges2) <- c("value","source","target")
indx  <- c(0,1,2,3,4,5)
ID    <- c('CITY_1','CITY_2','CITY_3','CITY_4','CITY_5','CITY_6')
nodes <-data.frame(cbind(ID,indx))

ui <- dashboardPage(
  dashboardHeader(
  ),
  dashboardSidebar(disable = TRUE),
  dashboardBody(
    fluidPage(
      useShinyalert()
      ,actionLink("savebtn", "Save button")
      ,sankeyNetworkOutput("simple")
    )
  )
)

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

  # Show modal when button is clicked.
  observeEvent(input$savebtn, {
    shinyalert("Save successful")
  })

  output$simple <- renderSankeyNetwork({
    sankeyNetwork(Links = edges2, Nodes = nodes,
                  Source = "source", Target = "target",
                  Value = "value",  NodeID = "ID" 
                  ,units = "SSN" )
  })
}

shinyApp(ui = ui, server = server)
DeanAttali
  • 25,268
  • 10
  • 92
  • 118
  • 1
    Shinyalert wont solve my problem,Actually here I have posted a trimmed version of code for issue recreation, In actual code, I have "textInput" in modalDialog, on click of button I want user to input text in textbox. Any suggestions on how to open modeldialog will be helpful. – Sourabh Kumar Sep 18 '17 at 04:44
  • Actually if you need a text input, then that also can be solved with shinyalert. Example: `shinyalert("hello", type = "input", callbackR = function(value) { cat(value) })`. I don't have time to debug shiny and networkD3, but I'm just offering this alternative as it might work for you. – DeanAttali Sep 19 '17 at 00:44
0

UPDATE (2019.05.20)

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


This issue has already been reported here, and I believe it's similar to what was reported here. The JavaScript used by sankeyNetwork() adds a <foreignObject><xhtml:body>... to wrap the SVG titles to facilitate multi-line titles in older versions of IE. That structure apparently conflicts with what bootstrap-datepicker does, and after a little bit of testing, I can verify that this seems to be at the root of what is happening here as well. There is a pull request already that should fix this on the networkD3 end, but it has not been vetted and merged yet. Once it has, installing and using the dev version of networkD3 should resolve this problem. I think this should also be fixed upstream since the <foreignObject><xhtml:body>... structure seems to be valid HTML/SVG.

CJ Yetman
  • 8,373
  • 2
  • 24
  • 56