You could use htmlwidgets::onRender()
to inject some JavaScript to add the value to the node label...
library(dplyr)
library(networkD3)
library(htmlwidgets)
#>
#> Attaching package: 'htmlwidgets'
#> The following object is masked from 'package:networkD3':
#>
#> JS
datosankey <-read.csv("https://docs.google.com/spreadsheets/d/e/2PACX-1vS45SekhiRvzq8PXATIpG9HjwqNBloVGBuey4Zmf7eM0CPTFKGeT7ZnB_KaSKml_gPF5gzt5nHFbQUs/pub?output=csv")
datosankey$target <- paste(datosankey$target, " ", sep = "")
nodes <- data.frame(name = unique(c(datosankey$source, datosankey$target)))
datosankey$IDsource = match(datosankey$source, nodes$name) - 1
datosankey$IDtarget = match(datosankey$target, nodes$name) - 1
sankey <-
sankeyNetwork(
Links = datosankey,
Nodes = nodes,
Source = "IDsource",
Target = "IDtarget",
Value = "value",
NodeID = "name",
sinksRight = FALSE,
nodeWidth = 60,
fontSize = 9,
nodePadding = 7
)
onRender(
x = sankey,
jsCode = '
function(el, x){
d3.select(el).selectAll(".node text")
.text(d => d.name + " (" + d3.format("(.0f")(d.value) + ")");
}
'
)