Skip to content

Resizable, minimal, embeddable output from plotly.offline.plot #1043

Closed
@mchels

Description

@mchels

In plotly.offline.plot is it intentional that resizing is only available for output_type == 'div' if plotly.js is included in the output: https://github.com/plotly/plotly.py/blob/master/plotly/offline/offline.py#L526-L537

This means that currently you cannot generate a minimal (no plotly.js), embeddable (output_type == 'div') script that is also resizable which seems not to be the intention in the PR that made the change: #717

Example:

import plotly
import plotly.graph_objs as go

figure_or_data = {
    "data": [go.Scatter(x=[1, 2, 3, 4], y=[4, 3, 2, 1])],
    "layout": go.Layout(title="hello world"),
}
fig_div = plotly.offline.plot(
    figure_or_data,
    image_width='100%',
    image_height='100%',
    include_plotlyjs=False,
    output_type='div',
    auto_open=False,
)

gives for fig_div:

'<div id="0b3aff81-1632-4ea9-a11f-a6b0b1cd02c1" style="height: 100%; width: 100%;" class="plotly-graph-div"></div><script type="text/javascript">window.PLOTLYENV=window.PLOTLYENV || {};window.PLOTLYENV.BASE_URL="https://plot.ly";Plotly.newPlot("0b3aff81-1632-4ea9-a11f-a6b0b1cd02c1", [{"type": "scatter", "x": [1, 2, 3, 4], "y": [4, 3, 2, 1]}], {"title": "hello world"}, {"showLink": true, "linkText": "Export to plot.ly"})</script>'

Setting include_plotlyjs=True gives at the end

<script type="text/javascript">window.addEventListener("resize", function(){Plotly.Plots.resize(document.getElementById("ba33b0b5-156d-4224-b931-414fcf0f02f1"));});</script></div>'

Apologies if I'm missing something obvious.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions