绘制表格子图禁用拖动列

问题描述 投票:0回答:1

我有 2 个情节子图,一个曲面图和一个表格图。默认情况下,表格图具有可以拖动和移动的列,我想禁用此功能,我找到了命令

config = {'staticPlot': True} 
fig.show(config=config) 

有效,但这也会影响无法正确显示的曲面图。如何仅在表格子图上设置此配置? 还有一种方法可以让表格表现得像常规 html 文本一样,我可以在其中选择和复制值?现在它就像一个图像我无法选择一个单元格。谢谢你

fig = make_subplots(
rows=2, cols=1,
row_heights=[0.9, 0.5],
vertical_spacing=0.03,
specs=[[{"type": "surface"}],
       [{"type": "table"}]])


fig_table = go.Table(
    header=dict(
        values=[""] + desired_x_axis,
        font=dict(size=12),
        align="left"
    ),
    cells=dict(
        font=dict(size=11),
        values=z_values,
        align = "left",
        fill=dict(color=['#ced9e4','#F0F8FF']))
    
        
)

config = {'staticPlot': True} 
fig.show(config=config) 
plotly plotly-python
1个回答
1
投票

我一直在寻找一种 Plotly 功能来轻松禁用这种拖放行为一段时间,但我没有找到任何东西。实现它的一个简单方法 - 仅适用于第一个表,可扩展给其他表 - 是将这个 JavaScript 行添加到代码中(我使用函数

include_plotlyjs
的参数
fig.to_html()
,但应该还有其他方法):

document.getElementsByClassName("table")[0].style.pointerEvents = "none";

有了这个就不需要包含

{'staticPlot': True}

© www.soinside.com 2019 - 2024. All rights reserved.