r - 在 R Shiny flexdashboard 中单击带有 Plotly 的直方图栏上的超链接悬停文本
问题描述
我创建了一个直方图,可以为每个条形显示几个超链接。但是,在我能够单击它们之前,悬停文本一直消失。这里有一个类似的问题:Open Link on Datapoint Click with Plotly in R Shiny,但我需要在图上显示要单击的名称。
任何帮助将不胜感激
library("data.table")
library("dplyr")
library("ggplot2")
term_id = c("label1", "label2")
term_name = c("soap", "vanila")
adjust_pvalue = c(0,0)
freq = c(2,5)
ratio = c("(2/95)", "(5/13)")
pvalue = c(0,0)
links = c("<a href='https://en.wikipedia.org/wiki/SOAP'>SOAP</a>, <a href='https://es.wikipedia.org/wiki/Jab%C3%B3n'>Jabon</a>",
"<a href='https://en.wikipedia.org/wiki/Multilayer_perceptron'>MP</a>, <a href='https://es.wikipedia.org/wiki/Vanilla'>flower</a>")
mytable = data.frame(term_id = term_id, term_name = term_name, adjust_pvalue = adjust_pvalue,
freq = freq,
ratio = ratio, pvalue = pvalue, links = links)
p <- mytable %>%
# prepare text for tooltip
dplyr::mutate(text = paste("ID Number: ", term_id, "\nTerm: ", term_name, "\nGene Ratio: ", ratio, "\nAdjust pvalue: ", adjust_pvalue, "\nCommon genes: ", links)) %>%
# Classic ggplot
ggplot( ggplot2::aes(x= freq , y= reorder(paste0("",term_id,": ",term_name,""), -adjust_pvalue), fill = adjust_pvalue, text=text)) +
theme (text = element_text(size= 8)) +
geom_bar(stat="identity", alpha=0.7) +
scale_fill_gradientn(colours = rainbow(2), trans= "log") +
theme(legend.position="right") +
labs(title = "My Analysis", x = "Number", y = "", fill = "p.value") + #
theme(plot.title = element_text(size = 15),
axis.title.x = element_text(size = 10),
axis.title.y = element_text(size = 10),
axis.text = element_text(
angle = 0))
# turn ggplot interactive with plotly layout.title
newgg <- ggplotly(p, tooltip="text") %>%
config(mathjax = "cdn",
toImageButtonOptions = list(
format = "svg",
filename = "myplot",
width = 1000,
height = 600
)
)
newgg
非常感谢!
解决方案
推荐阅读
- typescript - 在 Angular 6 中使用 clearInterval() 停止刷新功能不起作用?
- angular - Angular 库:单独的 HttpInterceptor
- c# - 为什么CPU使用率不增加?
- javascript - 回调里面的Javascript removeEventListner?
- c# - WPF 窗口视觉效果
- javascript - 淘汰计算函数称为“为时已晚”......?
- html - 我无法使用 CSS 设置背景图像
- javascript - 更改已具有特定背景颜色的任何 TD 的背景颜色
- django - 带有奇怪标签的 Django Rest
- android - 如何将隐藏文件分享到 Whatsapp?