Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added get_plotlyjs and get_plotlyjs_version functions #1246

Merged
merged 2 commits into from
Oct 29, 2018
Merged

Conversation

jonmmease
Copy link
Contributor

Implements suggestion from #637, introducing a public docstring-documented plotly.offline.get_plotlyjs function that returns the contents of the bundled version of plotly.js.

Motivating use-case from the new get_plotlyjs docstring :

Here is an example of creating a standalone HTML report that contains
two plotly figures, each in their own div. The include_plotlyjs argument
is set to False when creating the divs so that we don't include multiple
copies of the plotly.js library in the output. Instead, a single copy
of plotly.js is included in a script tag in the html head element.

    >>> import plotly.graph_objs as go
    >>> from plotly.offline import plot, get_plotlyjs
    >>> fig1 = go.Figure(data=[{'type': 'bar', 'y': [1, 3, 2]}],
    ...                 layout={'height': 400})
    >>> fig2 = go.Figure(data=[{'type': 'scatter', 'y': [1, 3, 2]}],
    ...                  layout={'height': 400})
    >>> div1 = plot(fig1, output_type='div', include_plotlyjs=False)
    >>> div2 = plot(fig2, output_type='div', include_plotlyjs=False)

    >>> html = '''
    ... <html>
    ...     <head>
    ...         <script type="text/javascript">{plotlyjs}</script>
    ...     </head>
    ...     <body>
    ...        {div1}
    ...        {div2}
    ...     </body>
    ... </html>
    ...'''.format(plotlyjs=get_plotlyjs(), div1=div1, div2=div2)

    >>> with open('multi_plot.html', 'w') as f:
    ...      f.write(html)

Additionally, this PR also introduces a new plotly.offline.get_plotlyjs_version function that returns the semantic version of the Plotly.js bundled that is included with plotly.py. This version string is updated automatically when the version of plotly.js is updated by the updatebundle setup.py command.

This function returns the plotly.js versions that is bundled with
plotly.py. The returned version is updated automatically during the
updatebundle setup.py command.
@jonmmease jonmmease added this to the v3.4.0 milestone Oct 27, 2018
@jonmmease jonmmease merged commit 01c65e1 into master Oct 29, 2018
michaelbabyn pushed a commit to michaelbabyn/plotly.py that referenced this pull request Dec 22, 2018
* Make get_plotlyjs public and add docstring
* Added plotly.offline.get_plotlyjs_version() function.
  This function returns the plotly.js versions that is bundled with plotly.py.
  The returned version is updated automatically during the updatebundle setup.py command.
@nicolaskruchten nicolaskruchten deleted the enh_637 branch June 19, 2020 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant