Skip to content

init_notebook_mode(connected=False) and pio.renderers.default='notebook' should not include full plotly.js on each call, but should check if already loaded #1531

Closed
@ociule

Description

@ociule

The current js generated by init_notebook_mode(connected=False) is naive: it includes a require.undef("plotly") to remove plotly and the full plotlyjs code to create it again. This adds 6MB for each call to init_notebook_mode to the notebook size. It also makes opening the notebook slower.

Including it once should be enough.

def iplot_my_thing():
    init_notebook_mode(connected=False)
    xs = [0, 1, 2, 3, 4]
    ys = [4, 3, 2, 1, 0]
    trace = go.Scatter(
        x = xs,
        y = ys,
        mode = 'markers'
    )
    data = [trace]
    plotly.offline.iplot(data)

Now just call iplot_my_thing twice, in two different jupyter cells. Save the notebook after each call and check its size.

The code shown wraps init_notebook_mode and iplot. This is necessary so calls to iplot_my_thing work under all circumstances, including users that load a notebook without restarting the kernel and not running the cell containing init_notebook_mode.

If this js fix is implemented, plotly.offline.iplot could just call init_notebook_mode directly and init_notebook_mode would not be needed in the public plotly API which would be a better UX.

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