简体   繁体   English

如何在 Python Flask 中隐藏使用 plotly 生成的内容

[英]How to hide produced with plotly in Python Flask

I am building a simple analytics application with Flask.我正在使用 Flask 构建一个简单的分析应用程序。 I need to hide the produced with plotly.我需要隐藏制作的情节。 And from the docs.从文档中。 The only option I see to hide is with the fig.show(config={"displaylogo": False}) unfortunately this will not work inside the app as it will open as a separate tab rather than inside the application.我看到隐藏的唯一选项是使用fig.show(config={"displaylogo": False})不幸的是,这在应用程序内不起作用,因为它将作为单独的选项卡而不是在应用程序内打开。

Below is my plot to render the plotly figure as a JSON下面是我将情节图呈现为 JSON 的情节

def plot_channel_contribution(path):
    data = pd.read_excel(
        path,
        sheet_name="Pie Chart Contribution",
        index_col=0,
        encoding="latin-1",
    )
    data = data.reset_index()
    fig = px.pie(
        data, values="Total Contribution", names="Channel", title="Channel Contribution"
    )

    fig.update_layout(
        title_x=0.5,
        autosize=False,
        width=1000,
        height=600,
    )
    return json.dumps(fig, cls=plotly.utils.PlotlyJSONEncoder)

In JS, I have tried:在 JS 中,我尝试过:

<script type="text/javascript">
      var graph = {{plotly_fig| safe}};
      Plotly.plot('plotly-figure-id',graph, {}, {displaylogo: false});
</script>

But nothing works, any tips or suggestions please?但是没有任何效果,请问有什么提示或建议吗?

I found the solution to be in JS:我发现解决方案在 JS 中:

var graph = {{plotly_fig| safe}};

graph.config={displayModeBar: false}

Plotly.newPlot('plotly-figure-id',graphs,{});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM