无法将高品质美学映射到反应性对象元素

Having trouble mapping highcharter aesthetics to reactive object elements

我有一个闪亮的大型应用程序,允许用户使用同一组初始选择的参数同时过滤 API 和 spark table 聚合(转储到 .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

我的 highcharter 调用似乎没有像我期望的那样对美学进行分组和着色:

        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")

你可能会说,我很困惑 where/how 映射 x 分组 udpatedTimeHour,或者适当地为不同的 direction 级别着色,并确保它们的 group 最终正确映射到图例和悬停中的标签。

我还尝试使用 hcaes() 调用来映射这些美学,我在某些文档中看到它作为 hc_add_series() 的参数包含在内,但我收到错误消息说该参数不是(还有吗?)在 hc_ 函数中命名...

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

您正在尝试将多个对象添加为一个系列,这就是不起作用的原因。只需稍微更改您的代码并使用 "magic" 函数 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")