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

168
Views
R-Shiny: ¿Cómo mostrar una animación y los controles creados con la función saveHTML()?

Hice un widget HTML en R que se anima a través de una serie de imágenes png usando la función saveHTML como esta:

 library(animation) saveHTML({ # List of the images in the 'images' directory image.list <- list.files('images', pattern = '*.png', full.names = TRUE) # Loop through and rename this for the animation to recognise it for (k in 1:length(image.list) ){ file.rename(image.list[k], sprintf(ani.options('img.fmt'), k)) } } , use.dev = FALSE, ani.width = 640, ani.height = 480, ani.type = 'png', interval = 2, single.opts = "'dwellMultiplier': 1")

Esto crea un objeto html llamado index.html en mi directorio de trabajo. Cuando hago doble clic aquí, se abre un navegador de Internet y uso los controles para animar los archivos .png que estaban en la carpeta "imágenes".

Mi pregunta es, ¿cómo renderizo esto en una aplicación R shiny?

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

0

Mi primera idea fue usar includeHTML , pero luego uno rápidamente se encuentra con problemas con las rutas de los archivos. Una solución rápida sería usar un <iframe> (con todos sus pros y contras). Todo lo que tiene que hacer es asegurarse de que la carpeta del HTML guardado y la carpeta de la imagen se conozcan en shiny . Lo más fácil es colocar imágenes y la carpeta www predefinida (que se conoce) y agregar la root como recurso:

 library(animation) library(shiny) tmpd <- tempdir() tmpd <- gsub("\\\\", "/", tmpd) tmpd <- file.path(tmpd, "animation") if (!dir.exists(tmpd)) dir.create(tmpd) tmpf <- file.path(tmpd, "random.html") ## use relative path for image dir imgd <- "www" ## need to switch working dir such that: ## saveHTML places the pics in the right location _AND_ uses relative paths setwd(tmpd) ## A quick and dirty demo des <- c("This is a silly example.\n\n", "You can describe it in more detail.", "For example, bla bla...") saveHTML({ par(mar = c(4, 4, 0.5, 0.5)) for (i in 1:20) { plot(runif(20), ylim = c(0, 1)) ani.pause() } }, img.name = "unif_plot", imgdir = imgd, htmlfile = tmpf, autobrowse = FALSE, title = "Demo of 20 uniform random numbers", description = des) ## add root dir as resource path addResourcePath("animation", tmpd) ## include as iframe shinyApp(fluidPage(tags$iframe(src="/animation/random.html", style = "height:99vh; width: 99vw; border:0")), function(...) {})
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!