[英]rbokeh hover tooltips - NSE getting in the way
I'm trying to make a customized tooltip in rbokeh but when I try to do it programatically the non-stadard evaluation gets in the way. 我正在尝试在rbokeh中创建自定义的工具提示,但是当我尝试以编程方式进行操作时,非标准评估会遇到麻烦。
From the example: 从示例:
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 helpfully fills in @model
and @hp
with the variables when hovering. 悬停时,Rbokeh有助于使用变量填充
@model
和@hp
。 However, when I try to make the hover use a character string that I can change on the fly, for example: 但是,当我尝试使悬停使用可以随时更改的字符串时,例如:
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 doesn't correctly fill in the variables in the tooltip. rbokeh无法正确填写工具提示中的变量。
How can I get rbokeh to treat hover_text
the same as the original character string? 如何使rbokeh将
hover_text
与原始字符串相同?
I've tried a couple of variations of do.call
, but all of them have had errors. 我尝试了
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
And 和
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
figured it out, pryr::subs()
and eval()
were the key. 弄清楚了,
pryr::subs()
和eval()
是关键。
pryr::subs(
figure() %>%
ly_points("disp", "mpg", data = mtcars, color = "cyl",
hover = hover_text)
) %>%
eval()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.