当我使用全局变量作为输入时,Highchart不会绘图

时间:2019-03-05 22:42:52

标签: r highcharts shiny shinydashboard r-highcharter

我正在使用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"))

enter image description here

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

enter image description here

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

enter image description here

1 个答案:

答案 0 :(得分:0)

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

此代码应该有效