rbokeh 悬停工具提示 - NSE 妨碍
rbokeh hover tooltips - NSE getting in the way
我正在尝试在 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
想通了,pryr::subs()
和 eval()
是关键。
pryr::subs(
figure() %>%
ly_points("disp", "mpg", data = mtcars, color = "cyl",
hover = hover_text)
) %>%
eval()
我正在尝试在 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
想通了,pryr::subs()
和 eval()
是关键。
pryr::subs(
figure() %>%
ly_points("disp", "mpg", data = mtcars, color = "cyl",
hover = hover_text)
) %>%
eval()