【问题标题】:Highchart Does Not Plot when I use Global Variables as Inputs当我使用全局变量作为输入时,Highchart 不绘图
【发布时间】:2019-07-27 12:13:01
【问题描述】:

我正在创建一个使用 HighChart 作为绘图工具的函数。但是,当我在 hcaes() 函数中使用全局变量时,什么都没有绘制。让我们以 mtcars 数据集为例。

x = "mpg"
y = "hp"
hchart(mtcars, "point", hcaes(x = x, y = y, group = "cyl"))

#I am also attempting
hchart(mtcars, "point", hcaes(x = eval(x), y = eval(y), group = "cyl"))

#this works but, I want to use variables rather than the actual string.
hchart(mtcars, "point", hcaes(x = "mpg", y = "hp", group = "cyl"))

#The output I would like to see is 
 x = "mpg"
 y = "hp"
 hchart(mtcars, "point", hcaes(x = x, y = y, group = "cyl"))

【问题讨论】:

  • 为什么这被否决了?有人可以生成一些可行的代码吗?
  • 嗨。你的问题问得很好,我不知道为什么有人反对它。我试过但无法让它工作。我认为这是更多的 R 问题,而不是 Highcharts。也许您应该尝试在 R 支持论坛上创建一个主题?

标签: r highcharts shiny shinydashboard r-highcharter


【解决方案1】:
 x = "mpg"
 y = "hp"
 # x = enexpr(x) you may want to use that, not mandatory
 # y = enexpr(y) you may want to use that  not mandatory

 hchart(mtcars, "point", hcaes(x = !! x, y = !! y, group = "cyl"))

这段代码应该可以工作

【讨论】:

  • 感谢您添加答案!如果您添加一个解释为什么这个解决方案有效以及它的作用可能会有所帮助,这样其他人就可以准确地理解为什么他们应该这样做。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-06
相关资源
最近更新 更多