r - 在悬停模板中添加自定义数据(情节,闪亮,r)
问题描述
我想在闪亮的应用程序中修改 plotly-sankey 图的标签。
例如,我想在悬停信息value
的<extra>
框中显示 1/10。在下面找到一个最小的工作示例。
该手册对以下内容中的其他详细信息进行了说明hovertemplate
:
可用的变量是作为此链接https://plot.ly/javascript/plotlyjs-events/#event-data
hovertemplate
中描述的事件数据发出 的变量。此外,每个点可以指定的每个属性(那些 )都是可用的。arrayOk: true
hovertemplate
或者,如果可能的话,我很乐意在字符串本身中除以 10 。
(非)工作示例:
rm(list = ls())
if(!require(pacman)) install.packages("pacman")
pacman::p_load(shiny, plotly)
# ui ----------------------------------------------------------------------
ui <- fluidPage(
fluidRow(
plotlyOutput("sankey")
)
)
# server ------------------------------------------------------------------
server <- function(input, output, session) {
output$sankey <- renderPlotly(
plot_ly(
type = "sankey",
orientation = "h",
node = list(
label = c("A1", "A2", "B1", "B2", "C1", "C2"),
color = c("blue", "blue", "blue", "blue", "blue", "blue"),
pad = 15,
thickness = 20,
line = list(
color = "black",
width = 0.5
)
),
link = list(
source = c(0,1,0,2,3,3),
target = c(2,3,3,4,4,5),
value = c(8,4,2,8,4,2),
customInfo = c(8,4,2,8,4,2)/10,
hovertemplate = "%{value}<extra>%{customInfo}</extra>"
)
) %>%
layout(
title = "Basic Sankey Diagram",
font = list(
size = 10
)
)
)
}
shinyApp(ui = ui, server = server)
解决方案
推荐阅读
- c# - 总阶段 I2C
- javascript - 如何将包含日期的一维数组划分为几个较小的数组(二维数组)
- javascript - 使用参数调用父函数
- javascript - 检查对象中的数组内的数字是否
- java - 当我尝试在 Vaadin 视图中初始化方法时,我得到 java.lang.NullPointerException: null
- azure - Azure SQL - 使用 ADO.NET 时的默认隔离级别
- java - 如何将类型作为变量传递?
- reactjs - Passport faillureRedirect 没有重定向,而是破坏了我的 React 应用程序
- excel - 单线(无 VBA)评估 IP 地址在哪个 VLAN 中
- java - 在java中使用递归的河内塔