Skip to content

Raise warning in plotly.offline.plot when output_type='file' and include_plotlyjs=False #1227

Closed
@capelastegui

Description

@capelastegui

When calling plotly.offline.plot(), if we use output_type='file' and include_plotlyjs=False, the resulting html file is useless, as it cannot be rendered.

I'm using plotly 3.3.0.

import plotly
import plotly.graph_objs as go

#This generates a file that includes plotly.js, and works as intended
plotly.offline.plot([go.Scatter(x=[1, 2, 3], y=[3, 2, 6])], 
                    filename='my-graph.html', output_type='file',
                   include_plotlyjs=True)

#This generates a file that doesn't include plotly.js, but fails to render
plotly.offline.plot([go.Scatter(x=[1, 2, 3], y=[3, 2, 6])], 
                    filename='my-graph-nojs.html', output_type='file', 
                    include_plotlyjs=False)

According to the documentation:

    include_plotlyjs (default=True) -- If True, include the plotly.js
        source code in the output file or string.
        Set as False if your HTML file already contains a copy of the plotly.js
        library.

I guess we are not supposed to use include_plotly_js=False and output_type='file' at the same time? If that is the case, the function should probably raise an error, rather than generating a useless file. However, I think the ideal solution would be to have the standalone html load plotly.js from an online CDN, like we do in Jupyter notebooks after calling init_notebook_mode(connected=False). So we would insert something like the following block in the html file:

<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions