首页 > 解决方案 > 在R中的highchart内循环

问题描述

我必须自动分析 RStudio 上的数据集。

我的问题是我不知道数据集中会有多少系列。所以我想知道是否可以在 Highcharts 内部做一个 for 循环?

我不知道它不起作用是因为我做错了什么还是因为不可能。

output$hc2 <- renderHighchart ({
Hchc <- highchart(hcaes(x = Spring ,y = Ponctuation)) %>% 
  hc_title(text = "Cumulation of the result of a Team per spring",
           margin = 20, align = "left",
           style = list(color = "#FE8000", useHTML = TRUE)) %>% 
  hc_xAxis(categories = tableA$Spring, title = list(text = "Number of spring",color = "#FE8000")) %>%
  hc_yAxis(title = list(text = "Cumulation of the result", color = "#FE8000"))%>% 

  for (i in length(mylist)){
    hc_add_series(name = name[i], data = mylistcumu[[i]]$CumuPonct) }

print(Hchc)})

标签: rloopshighchartsrstudioshinydashboard

解决方案


我发现 !

output$hc2 <- renderHighchart ({
Hchc <- highchart(hcaes(x = Spring ,y = Ponctuation)) %>% 
hc_title(text = "Cumulation of the result of a Team per spring",
           margin = 20, align = "left",
           style = list(color = "#FE8000", useHTML = TRUE)) %>% 
hc_xAxis(categories = tableA$Spring, title = list(text = "Number of spring",color = "#FE8000")) %>%
hc_yAxis(title = list(text = "Cumulation of the result", color = "#FE8000"))

for (i in 1:length(mylist)){
  Hchc <- Hchc %>%
   hc_add_series(name = name[i], data = mylistcumu[[i]]$CumuPonct) }

Hchc})

推荐阅读