1

我正在尝试在 rbokeh 中制作自定义工具提示,但是当我尝试以编程方式进行时,非标准评估会妨碍我。

从例子:

library(rbokeh)

mtcars$model <- row.names(mtcars)
figure() %>%
  ly_points(disp, mpg, data = mtcars, color = cyl,
            hover = "This <strong>@model</strong><br>has @hp horsepower!")

Rbokeh 有助于在悬停时填充@model变量@hp。但是,当我尝试使悬停时使用可以即时更改的字符串,例如:

hover_text <- "This <strong>@model</strong><br>has @hp horsepower!"
mtcars$model <- row.names(mtcars)
figure() %>%
  ly_points(disp, mpg, data = mtcars, color = cyl,
            hover = hover_text)

rbokeh 未正确填写工具提示中的变量。

如何让 rbokeh 将hover_text其视为与原始字符串相同?


我已经尝试了几种变体do.call,但它们都有错误。

ly_points_docall <- function(...) {
  do.call(ly_points, list(..., hover = hover_text))
}

figure() %>%
  ly_points_docall(disp, mpg, data = mtcars, color = cyl,
                   hover = hover_text)
#  Error in do.call(ly_points, list(..., hover = hover_text)) : 
#  object 'disp' not found 

ly_points_docall <- function(...) {
  do.call(ly_points, list(..., hover = hover_text))
}

figure() %>%
  ly_points_docall(~disp, ~mpg, data = mtcars, color = ~cyl,
                   hover = hover_text)
# Error in (function (fig, x, y = NULL, data = figure_data(fig), glyph = 21,  : 
#   formal argument "hover" matched by multiple actual arguments 
4

1 回答 1

1

想通了,pryr::subs()eval()关键。

pryr::subs(
  figure() %>% 
    ly_points("disp", "mpg", data = mtcars, color = "cyl",
              hover = hover_text)
) %>% 
  eval()
于 2017-01-03T17:23:33.213 回答