How to loop output plotly graphs

Hello,
I made a loop to make 15 radar.
I would like each graphic to be exported to a file on my computer at the end of each loop.
How can I do that?
Thank you in advance

Here is my R code :
for (i in 1:(ncol(moyspe))) {
radarspe <- plot_ly(
type = 'scatterpolar',
fill = 'toself'
) %>%
add_trace(
r = moyspe[,i],
theta = c("vitesse", "gainage", "equilibre", "souplesse",
"force_membres_inf", "force_membres_sup", "endurance"),
name = names(moyspe[i])
) %>%
add_trace(
r = moytest$apply(final[, c(8, 10, 12, 14, 16, 18, 20)], 2, mean, na.rm = T),
theta = c("vitesse", "gainage", "equilibre", "souplesse",
"force_membres_inf", "force_membres_sup", "endurance"),
name = 'Moyenne'
) %>%
layout(
polar = list(
radialaxis = list(
visible = T,
range = c(0,20)
)
)
)
}

Hi @Marceau. You may try to export the each plotly by plotly_IMAGE function. The following are the sample code. Hope it can help.

for (i in 1:(ncol(moyspe))) {
  radarspe <- plot_ly(
    type = 'scatterpolar',
    fill = 'toself'
  ) %>%
    add_trace(
      r = moyspe[,i],
      theta = c("vitesse", "gainage", "equilibre", "souplesse",
                "force_membres_inf", "force_membres_sup", "endurance"),
      name = names(moyspe[i])
    ) %>%
    add_trace(
      r = moytest$apply(final[, c(8, 10, 12, 14, 16, 18, 20)], 2, mean, na.rm = T),
      theta = c("vitesse", "gainage", "equilibre", "souplesse",
                "force_membres_inf", "force_membres_sup", "endurance"),
      name = 'Moyenne'
    ) %>%
    layout(
      polar = list(
        radialaxis = list(
          visible = T,
          range = c(0,20)
        )
      )
    ) %>%
    plotly_IMAGE(format = "png", out_file = paste0("output_", i, ".png"))
}
1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.