-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
📚 DOCS: Added a plotly example. (#269)
- Loading branch information
1 parent
8da21d2
commit 4e308de
Showing
2 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
============== | ||
Plotly Example | ||
============== | ||
|
||
Thebe can display output from plotly.py_. | ||
|
||
.. _plotly.py: https://github.com/plotly/plotly.py | ||
|
||
Setup | ||
===== | ||
|
||
Be sure to load require.js before any of your thebe activation code so that the | ||
Jupyter widgets can function: | ||
|
||
.. code-block:: html | ||
|
||
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"></script> | ||
|
||
Configure thebe and load it: | ||
|
||
.. code-block:: html | ||
|
||
<script type="text/x-thebe-config"> | ||
{ | ||
requestKernel: true, | ||
binderOptions: { | ||
repo: "plotly/plotly.py", | ||
ref: "doc-prod", | ||
binderUrl: "https://binder.libretexts.org", | ||
repoProvider: "github", | ||
}, | ||
} | ||
</script> | ||
<script src="https://unpkg.com/thebelab@latest/lib/index.js"></script> | ||
|
||
Create a button to activate thebe: | ||
|
||
.. code-block:: html | ||
|
||
<button id="activateButton" style="width: 120px; height: 40px; font-size: 1.5em;"> | ||
Activate | ||
</button> | ||
<script> | ||
var bootstrapThebe = function() { | ||
thebelab.bootstrap(); | ||
} | ||
document.querySelector("#activateButton").addEventListener('click', bootstrapThebe) | ||
</script> | ||
|
||
Now add code cells between these HTML tags: | ||
|
||
.. code-block:: html | ||
|
||
<pre data-executable="true" data-language="python"></pre> | ||
|
||
Example | ||
======= | ||
|
||
.. raw:: html | ||
|
||
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"></script> | ||
<script type="text/x-thebe-config"> | ||
{ | ||
requestKernel: true, | ||
binderOptions: { | ||
repo: "plotly/plotly.py", | ||
ref: "doc-prod", | ||
repoProvider: "github", | ||
}, | ||
} | ||
</script> | ||
<script src="https://unpkg.com/thebelab@latest/lib/index.js"></script> | ||
|
||
Press the "Activate" button below to connect to a Jupyter server: | ||
|
||
.. raw:: html | ||
|
||
<button id="activateButton" style="width: 120px; height: 40px; font-size: 1.5em;"> | ||
Activate | ||
</button> | ||
<script> | ||
var bootstrapThebe = function() { | ||
thebelab.bootstrap(); | ||
} | ||
document.querySelector("#activateButton").addEventListener('click', bootstrapThebe) | ||
</script> | ||
|
||
Here is a distribution plot example from https://plotly.com/python/distplot/ | ||
(MIT License): | ||
|
||
.. raw:: html | ||
|
||
<pre data-executable="true" data-language="python"> | ||
import plotly.express as px | ||
df = px.data.tips() | ||
fig = px.histogram(df, x="total_bill", y="tip", color="sex", marginal="rug", | ||
hover_data=df.columns) | ||
fig.show() | ||
</pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters