我试图在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
答案 0 :(得分:0)
想通了,pryr::subs()
和eval()
是关键。
pryr::subs(
figure() %>%
ly_points("disp", "mpg", data = mtcars, color = "cyl",
hover = hover_text)
) %>%
eval()