我想在闪亮的应用程序中修改plotly-sankey图的标签。
例如,我想在悬停信息的value
框中显示<extra>
的1/10。
在下面找到一个最小的工作示例。
该手册在hovertemplate
中说明了其他详细信息:
hovertemplate
中可用的变量是作为 在此链接中描述的事件数据 https://plot.ly/javascript/plotlyjs-events/#event-data。另外, 每个点可以指定的每个属性(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)