Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

262
Views
r2d3 + Shiny: no puede renderizar una imagen local en D3, a pesar de poder renderizar una usando una URL

Estoy luchando para que r2d3 + Shiny renderice solo un archivo .png. Puedo hacerlo si uso una URL en el archivo .js, pero no se procesa nada si uso una ruta relativa hacia exactamente el mismo archivo, pero almacenado localmente. Por supuesto, he comprobado que existe el archivo local, que no hay errores tipográficos en la ruta, etc.

Creé una aplicación Toy R Shiny para reproducir el problema. Solo muestra un gráfico d3, que a su vez solo muestra el logotipo de RStudio en un archivo .png (comente o descomente las 2 últimas líneas del archivo .js para ver el problema). ¿Por qué está pasando eso? ¿Cómo hacer que se muestre una imagen local usando r2d3? He estado buscando una solución durante horas, en vano.

app.R

 library(r2d3) library(shiny) # Define UI for application that draws a histogram ui <- fluidPage( # Application title titlePanel("Reprex"), # Sidebar with a slider input for number of bins sidebarLayout( sidebarPanel( ), # Show a plot of the generated distribution mainPanel( d3Output("d3Chart", width = "100%", height = "800px") # d3output is the kind of output needed for D3; it requires renderD3 on the server side ) ) ) # Define server logic required to draw a histogram server <- function(input, output) { output$d3Chart <- renderD3({ # generate bins based on input$bins from ui.R r2d3(script = "./reprex.js", d3_version ="6") }) } # Run the application shinyApp(ui = ui, server = server)

reprex.js

 svg .append("image") .attr("class","expand") .attr("x", 0) .attr("y", 0) .attr('width', 50) .attr('height', 50) .style("opacity",1) .attr("xlink:href", "https://www.rstudio.com/wp-content/uploads/2018/10/RStudio-Logo.png"); // It works with that image but NOT with a local image. Why? //.attr("xlink:href", "./RStudio-Logo.png");

Estoy usando R-4.1.2 + RStudio 1.4.1717 para ejecutar la aplicación Shiny.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Gracias a Geovany, esto se resolvió. Agregué en app.R, antes de la función ui, addResourcePath("images", ".") , para poder acceder al directorio de trabajo en el que está almacenada mi imagen (aquí, donde se encuentra app.R) usando la etiqueta images . Reemplazando la última línea de reprex.js con .attr("xlink:href", "images/RStudio-Logo.png"); (y dejando comentada la línea anterior), se desplegaba la imagen.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!