christophergandrud / networkD3

D3 JavaScript Network Graphs from R
http://christophergandrud.github.io/networkD3
650 stars 269 forks source link

location.href in url(...) #226

Open MikeBadescu opened 6 years ago

MikeBadescu commented 6 years ago

Arrows do not work in WebKit (iPad, Safari) due to treatment of url(...) in WebKit. For this issue (and possible fixes), please see https://stackoverflow.com/a/29984481

I made one small change (added location.href) and now it seems to behave as expected.

Here is the sample Shiny app I used for testing. I have deployed it at https://numeract.shinyapps.io/test/ (it includes the suggested change).

require(shiny)
require(networkD3)

shiny::shinyApp(
    ui = bootstrapPage(
        networkD3::forceNetworkOutput(outputId = 'plot3')
    ),
    server = function(input, output) {

        data(MisLinks)
        data(MisNodes)

        output$plot3 <- networkD3::renderForceNetwork({
            forceNetwork(Links = MisLinks, Nodes = MisNodes, Source = "source",
                         Target = "target", Value = "value", NodeID = "name",
                             Group = "group", opacity = 1, arrows = TRUE)

        })
    }
)
cjyetman commented 6 years ago

I'm not opposed to this change, but the arrows work for me locally on macOS/Safari and don't when I publish it to shinyapps.io. Out of curiosity, does this have to do something with being in an iframe or something like that once it's published to shinyapps.io?

MikeBadescu commented 6 years ago

I am not JS expert, but based on the stackoverflow answer I expect it has something to do with the <base href=" ... "> declaration (see page source), which might be specific to shinyapps.io. I do not know yet if this is relevant to Shiny Server itself.

cjyetman commented 6 years ago

that makes sense, thanks