We have created sankey diagram to show flow between different cities via networkD3::sankeyNetwork()
in R.
We have received client requirement to show "state" name corresponding to city on tooltip/hover of sankey node.
In following code we want to show State value on tool-tip(hover) of node
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('CITY1','CITY2','CITY3','CITY4','CITY5','CITY6')
State <- c( 'IL','CA','FL','NW','GL','TX')
nodes <-data.frame(cbind(ID,indx,State))
ui <- dashboardPage(
dashboardHeader(
),
dashboardSidebar(disable = TRUE),
dashboardBody(
fluidPage(
sankeyNetworkOutput("simple")
)
)
)
server <- function(input, output,session) {
output$simple <- renderSankeyNetwork({
sankeyNetwork(Links = edges2, Nodes = nodes,
Source = "source", Target = "target",
Value = "value", NodeID = "ID"
,units = " " )
})
}
shinyApp(ui = ui, server = server)
As the networkD3
package does not provide a customized tooltip feature, please suggest how it can be achieved via javascript or some other way in networkD3::sankeyNetwork()
.