我有一个相对简单的sankey图表,使用networkD3
包在闪亮的应用程序中生成。
我面临的问题是,根据我的输入数据,输出图的尺寸(高度和宽度)会有很大差异。请查看下面的gif以查看行为。
MWE代码:
library("shiny")
library("networkD3")
ui <- fluidPage(
column(3,
sliderInput("f1", "Factor:",
min = 1, max = 100, value = 1, step = 1,
animate = animationOptions(interval = 1, loop = FALSE))
),
column(6, sankeyNetworkOutput("mySankeyD", width = "100%", height = "100%")),
column(3, "")
)
server <- function(input, output) {
output$mySankeyD <- renderSankeyNetwork({
myDf <- list(nodes = data.frame(name=c( "A", "B", "C", "D",
"W", "X", "Y", "Z")),
links = data.frame(source=as.integer(c(0, 0, 0, 0, 1, 2, 3)),
target=as.integer(c(4, 5, 5, 5, 7, 6, 5)),
value =c(1*input$f1, 1, 1, 5, 1, 5, 3)
)
)
sankeyNetwork(Links = myDf$links, Nodes = myDf$nodes, Source = "source",
Target = "target", Value = "value", NodeID = "name",
units = "TWh", fontSize = 25, nodeWidth = 30, fontFamily = "sans-serif", iterations = 0,
nodePadding = 10, height = 500, width = 500, sinksRight =TRUE,
margin = NULL)
})
}
shinyApp(ui, server)
我尝试在height
函数内操作输入变量width
和sankeyNetworkOutput()
nodePadding
内的变体height
,width
,sinksRight
,margin
和sankeyNetwork()
。似乎没有人对地块大小产生一致的影响。
我还尝试将links dataframe
内部myDf
的值标准化为:
value = c(1*input$w1, 4, 1, 5, 1, 5, 3)/(1*input$w1)
或value = c(1*input$w1, 4, 1, 5, 1, 5, 3)/sum(c(1*input$w1, 4, 1, 5, 1, 5, 3))
但标准化根本没有任何区别。我认为value
的价值关系对情节维度有影响。但为什么呢?
我想念什么?为什么value
的值会影响绘图尺寸?
有人有解决方案或解决方法吗?