如何调整 R 中破折号图形的高度?
How to adjust height of dash plotly figures in R?
我有 3 个使用 ggplotly 和 dash 绘制的散点图。然后我使用 Dash 在选项卡中绘制了 3 个图形,但是图形的高度看起来被压扁了,我不知道如何增加它们的高度。
我用这样的代码制作了 3 个绘图图形 3 次:
p1 <- ggplot(data, aes(x=col1, y=col1))
plotlyp1 <- ggplotly(p1)
然后我用 3 个标签对破折号图进行编码,每个图一个标签,其中:
app <- Dash$new()
app$layout(htmlDiv(list(
htmlH1('3 plots'),
dccTabs(id="tabs-example", value='tab-1-example', children=list(
dccTab(label='plot1', value='tab-1-example'),
dccTab(label='plot2', value='tab-2-example'),
dccTab(label='plot3', value='tab-3-example')
)),
htmlDiv(id='tabs-plots')
)))
app$callback(
output = list(id='tabs-plots', property = 'children'),
params = list(input(id = 'tabs-example', property = 'value')),
function(tab){
if(tab == 'tab-1-example'){
return(htmlDiv(list(
htmlH3(''),
dccGraph(
id='graph-1-tabs',
figure=plotlyp1
)
)))
}
else if(tab == 'tab-2-example'){
return(htmlDiv(list(
htmlH3(''),
dccGraph(
id='graph-2-tabs',
figure=plotlyp2
)
)))
}
else if(tab == 'tab-3-example'){
return(htmlDiv(list(
htmlH3(''),
dccGraph(
id='graph-3-tabs',
figure=plotlyp3,
style = list(
height ='100%'),
)
)))
}
}
)
app$run_server()
目前为了获得更高的高度,我正在 dccGraph()
中尝试 style = list(height ='100%')
但这似乎没有任何作用,我在 R 中找不到任何 examples/resources显示如何更改地块高度。
作为参考,上面的破折号代码给出了这个:
每个选项卡都有这样的图,我只是想让它们按高度变大。
style = list(height = "100%")
会将 CSS height:100%
添加到包含图的 div
中。这会将绘图缩放到由 htmlDiv()
生成的父级 div
的 100% 高度。您可以放大父级:
if(tab == 'tab-1-example'){
return(htmlDiv(
style = list(height = '750px'), # <=
list(
htmlH3(''),
dccGraph(
id = 'graph-1-tabs',
figure = plotlyp1,
style = list(height = '100%')
)
)))
}
我有 3 个使用 ggplotly 和 dash 绘制的散点图。然后我使用 Dash 在选项卡中绘制了 3 个图形,但是图形的高度看起来被压扁了,我不知道如何增加它们的高度。
我用这样的代码制作了 3 个绘图图形 3 次:
p1 <- ggplot(data, aes(x=col1, y=col1))
plotlyp1 <- ggplotly(p1)
然后我用 3 个标签对破折号图进行编码,每个图一个标签,其中:
app <- Dash$new()
app$layout(htmlDiv(list(
htmlH1('3 plots'),
dccTabs(id="tabs-example", value='tab-1-example', children=list(
dccTab(label='plot1', value='tab-1-example'),
dccTab(label='plot2', value='tab-2-example'),
dccTab(label='plot3', value='tab-3-example')
)),
htmlDiv(id='tabs-plots')
)))
app$callback(
output = list(id='tabs-plots', property = 'children'),
params = list(input(id = 'tabs-example', property = 'value')),
function(tab){
if(tab == 'tab-1-example'){
return(htmlDiv(list(
htmlH3(''),
dccGraph(
id='graph-1-tabs',
figure=plotlyp1
)
)))
}
else if(tab == 'tab-2-example'){
return(htmlDiv(list(
htmlH3(''),
dccGraph(
id='graph-2-tabs',
figure=plotlyp2
)
)))
}
else if(tab == 'tab-3-example'){
return(htmlDiv(list(
htmlH3(''),
dccGraph(
id='graph-3-tabs',
figure=plotlyp3,
style = list(
height ='100%'),
)
)))
}
}
)
app$run_server()
目前为了获得更高的高度,我正在 dccGraph()
中尝试 style = list(height ='100%')
但这似乎没有任何作用,我在 R 中找不到任何 examples/resources显示如何更改地块高度。
作为参考,上面的破折号代码给出了这个:
每个选项卡都有这样的图,我只是想让它们按高度变大。
style = list(height = "100%")
会将 CSS height:100%
添加到包含图的 div
中。这会将绘图缩放到由 htmlDiv()
生成的父级 div
的 100% 高度。您可以放大父级:
if(tab == 'tab-1-example'){
return(htmlDiv(
style = list(height = '750px'), # <=
list(
htmlH3(''),
dccGraph(
id = 'graph-1-tabs',
figure = plotlyp1,
style = list(height = '100%')
)
)))
}