Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

172
Vistas
Text shadow on networkD3 using HTMLWidget

I built a Sankey diagram in R using networkD3 package and I wanted to add text-shadow to the node labels. Actually, what I need is for the text to be in some way outlined because my original data is very complex and some of the text gets confused with the "lines" connecting the nodes. This was the approach I found on StackOverflow that should work fine, but if anyone has any other idea, I am open for new approaches.

I found a question whose implementation seems to be very similar to mine: Bold text in R using networkD3 package

But when I try the same approach, nothing happens.

A generic data would be:

library(networkD3)
URL <- "https://cdn.rawgit.com/christophergandrud/networkD3/master/JSONdata/energy.json"
Energy <- jsonlite::fromJSON(URL)
sn <- sankeyNetwork(Links = Energy$links, Nodes = Energy$nodes, Source = "source",
              Target = "target", Value = "value", NodeID = "name",
              fontSize = 14, nodeWidth = 20, height = 900, width = 700, units = "px")

Like this, I tried on my own to use the onRender function of htmlwidgets but to no avail. As such, I adapted the code of the aforementioned topic but nothing changed in the generated widget:

library(htmlwidgets)
onRender(sn,
         '
  function(el) {
    d3.selectAll(".node text").attr("text-shadow", "1px 0 white, -1px 0 white, 0 1px white, 0-1px white")
  }
  '
)
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

To apply CSS styles, you need to use .style() instead of .attr()...

htmlwidgets::onRender(sn, jsCode = '
  function(el) {
    d3.selectAll(".node text").style("text-shadow", "1px 0 white, -1px 0 white, 0 1px white, 0 -1px white")
  }
')

enter image description here

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda