tm_animate does not return anything for rendered documents (e.g., rmd, qmd, reprex)
It would be great if it would render the animation directly in the qmd/rmd output.
library(tmap)
library(spData)
tm_shape(nz) +
tm_polygons() +
tm_animate("Name")
Yes, that would be great.
I don't know how. Normally the animation should be printed over here https://github.com/r-tmap/tmap/blob/master/R/tmap_animation.R#L174-L195
It does go there, but somehow nothing happens.
Maybe related to https://github.com/r-tmap/tmap/issues/989 ? Any idea @olivroy or @tim-salabim ?
Possibly gganimate could serve as an inspiration with its knit_print.gganim(x, options, ...) function (https://gganimate.com/reference/animate.html)
library(ggplot2)
library(gganimate)
ggplot(mtcars, aes(factor(cyl), mpg)) +
geom_boxplot() +
# Here comes the gganimate code
transition_states(
gear,
transition_length = 2,
state_length = 1
) +
enter_fade() +
exit_shrink() +
ease_aes('sine-in-out')

Hopefully, it works now, please test.
Works -- see https://tmap.geocompx.org/animations
There is still a minor issue: the animations do not render correctly when the quarto chunk has two (or more) animations at the same time.
See the code at https://github.com/geocompx/tmap/blob/15ceb827dd8303d5a4c1526642b4dd36f29dc4ba/animations.qmd#L42-L53 and the outcome at https://tmap.geocompx.org/animations#fig-anims.
Not sure if multiple animations in one chunk are supported (?) I basically took the code from gganimate and put it here to make it work. If gganimate works, then we can check where the difference comes from.
@mtennekes I confirm that this issue also applies to gganimate.
I do not know if this is helpful, but when the quarto code chunk layout has two or more figures, then they are saved independently with numeric suffixes (i.e., -1, -2, etc. see https://github.com/geocompx/tmap/blob/main/figures/fig-mproj-ortho-1.png and https://github.com/geocompx/tmap/blob/main/figures/fig-mproj-ortho-2.png). However, for the animation the second gif overwrites the first one using the -1 suffix -- see https://github.com/geocompx/tmap/blob/main/figures/fig-anims-1.gif (it should be fig-anims-1.gif and fig-anims-2.gif).
Have you noticed if this was a problem before. evaluate has been re-written last year. https://evaluate.r-lib.org/news/index.html#evaluate-100 and multiple bug fixes releases were done since then. I wonder if this reproduces with evaluate 0.24 and knitr 1.47.
Maybe we could open an issue on the gganimate side to see if this is something they noticed,
There is also this Open evaluate PR that may solve the issue at the end?
@olivroy evaluate 0.24 and knitr 1.47 -- the issue persists.
@olivroy that open pull request is also not helping here.
@olivroy -- any suggestions for the next step? I could open an issue, but I am unsure where (gganimate repo, quarto repo,etc.)