Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

171
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda