无法将高图美学映射到反应对象元素

时间:2017-03-14 15:16:48

标签: r highcharts shiny dplyr reactiveui

我有一个大型闪亮的应用程序,允许用户使用同一组初始选择参数同时过滤API和spark表聚合(转储到.Rdata)。将所有这些组合成一个可重复的例子将是艰难的,但是,这是分组和总结我感兴趣的度量的函数(试图拒绝让我粘贴partitionFiltered()):

df <- reactive({partitionFiltered() %>%
      dplyr::group_by(updatedTimeHour, direction) %>%
      dplyr::mutate(count_dir = sum(n_flows)) %>%
      dplyr::ungroup() %>%
      dplyr::select(updatedTimeHour, direction, count_dir) %>%
      dplyr::arrange(updatedTimeHour) %>% 
      unique()})

(最终,updatedTimeHourdirection将分别由input$periodicityinput$dimension取代,但这超出了此问题的范围。)

df()对象如下:

updatedTimeHour direction   count_dir
6               1           525071.00
6               2           3491.00
6               0           498816.00
6               3           5374.00
7               2           2432.00
7               0           303818.00
7               1           340768.00
7               3           4852.00
8               1           1969048.00

我的高潮呼唤似乎并没有像我期望的那样对美学进行分组和着色:

        hc <- highchart() %>% 
              hc_add_series(data = df()$count_dir, 
              type = input$plot_type,
              name = factor(df()$direction)
              showInLegend = TRUE,
              # ??group = df()$direction,
              # ??color = df()$direction,
              # ??x = df()$updatedTimeHour, y = df()$count_dir, color = df()$direction,
              # ??hcaes(x = df()$updatedTimeHour, y = df()$count_dir, color = df()$direction)
              ) %>%
              hc_xAxis(type = 'datetime',
                       # ??group = factor(df()$direction),
                       categories = df()$updatedTimeHour,
                       tickmarkPlacement = "on",
                       opposite = FALSE) %>%
              hc_title(text = "NetFlows, by Hour",
                       style = list(fontWeight = "bold")) %>% 
              hc_exporting(enabled = TRUE, filename = "threat_extract")

No groups or colors mapped to the 4 direction levels

正如您可能已经说过的那样,我对于在何处/如何映射x-grouping udpatedTimeHour非常困惑,或者对相应的direction级别进行了适当的着色,并确保他们的group最终正确映射到图例中的标签并悬停。

我还尝试使用hcaes()调用来映射这些美学,我在一些文档中将hc_add_series()作为hc_的参数包含在内,但我得到的错误是说该参数不是(任何更长?)在{{1}}函数中命名...

感谢任何帮助,相关问题为here

1 个答案:

答案 0 :(得分:2)

您正尝试将多个对象添加为多个对象,这就是为什么不起作用的原因。只需更改一下代码并使用“魔术”函数hchart就可以了:

df = data_frame(updatedTimeHour = c(6,6,6,6,7,7,7,7,8), direction = c(1,2,0,3,2,0,1,3,1), count_dir = rnorm(9))
type = "line"
hchart(df, type, hcaes(x = updatedTimeHour, y = count_dir, group = as.factor(direction))) %>% 
   hc_title(text = "NetFlows, by Hour",
       style = list(fontWeight = "bold")) %>% 
   hc_exporting(enabled = TRUE, filename = "threat_extract")

enter image description here