Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,40 @@
</tr>
</table>

---

## NOTE

__**This is a fork of Plotly modified for use in Mode's native Python notebook environment.**__

To test work on Mode's fork of Plotly you will need to do the following:

1. ensure these Mode services are running:

* Jiffypop: https://github.com/mode/go-mono/tree/master/jiffypop
* Python 3 runtime: https://github.com/mode/runtime-images/tree/master/runtime-python3
* The following services in the JVM mono repo: https://github.com/mode/jvm-mono
* DirectConnect
* Credguard
* Flamingo
* Zookeeper

2. After saving changes to the Plotly repo, if your local Python3 Docker container is running stop and restart it:
* Restart the container with `./runtime-python3/bin/run-runtime-python3-image-0` in the `runtime-images` directory

3. Execute this command within the `plotly.py` directory to apply your changes to the Python runtime:
`docker cp ./packages/python/plotly/. $(docker container ps --filter name=runtime-python3 -q):/opt/conda/envs/python3/lib/python3.6/site-packages/`

4. Click "Restart" in the web application notebook.

5. Verify you're running your local version of Plotly by executing this code in the notebook, which should print out `'0+unknown'`:
```
import plotly
plotly.__version__
```

---

## Quickstart

`pip install plotly "notebook>=5.3" "ipywidgets>=7.2"`
Expand Down Expand Up @@ -102,7 +136,7 @@ conda install "notebook>=5.3" "ipywidgets=7.5"

### JupyterLab Support (Python 3.5+)
For use in JupyterLab, install the `jupyterlab` and `ipywidgets`
packages using pip...
packages using pip...

```
pip install jupyterlab==1.0 "ipywidgets==7.5"
Expand Down
23 changes: 13 additions & 10 deletions packages/python/chart-studio/chart_studio/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,19 @@ def ensure_local_plotly_files():
if contents_orig.keys() != contents.keys():
utils.save_json_dict(fn, contents)

else:
warnings.warn(
"Looks like you don't have 'read-write' permission to "
"your 'home' ('~') directory or to our '~/.plotly' "
"directory. That means plotly's python api can't setup "
"local configuration files. No problem though! You'll "
"just have to sign-in using 'plotly.plotly.sign_in()'. "
"For help with that: 'help(plotly.plotly.sign_in)'."
"\nQuestions? Visit https://support.plot.ly"
)
# MODE MODIFIED #
# unless or until we support online plotly there's no reason to nag the user about
# something they can't affect anyway
# else:
# warnings.warn(
# "Looks like you don't have 'read-write' permission to "
# "your 'home' ('~') directory or to our '~/.plotly' "
# "directory. That means plotly's python api can't setup "
# "local configuration files. No problem though! You'll "
# "just have to sign-in using 'plotly.plotly.sign_in()'. "
# "For help with that: 'help(plotly.plotly.sign_in)'."
# "\nQuestions? Visit https://support.plot.ly"
# )


### credentials tools ###
Expand Down
41 changes: 34 additions & 7 deletions packages/python/plotly/plotly/io/_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def to_html(
then_animate = ""
if jframes:
then_addframes = """.then(function(){{
Plotly.addFrames('{id}', {frames});
window.Plotly && Plotly.addFrames('{id}', {frames});
}})""".format(
id=plotdivid, frames=jframes
)
Expand All @@ -230,14 +230,28 @@ def to_html(
# Serialize config dict to JSON
jconfig = json.dumps(config)

# MODE ADDITION #
after_script = """
.then(function() {{
if (window["MODE_PYTHON_EMBED"]) {{
window["mode"] && window["mode"].resize && window["mode"].resize();
}} else {{
window.onresize = function() {{
window.Plotly && Plotly.Plots.resize(document.getElementById("{id}"));
}};
}}
}});
""".format(id=plotdivid)

# MODE MODIFIED #
script = """
if (document.getElementById("{id}")) {{
Plotly.newPlot(
window.Plotly && Plotly.newPlot(
'{id}',
{data},
{layout},
{config}
){then_addframes}{then_animate}{then_post_script}
){then_addframes}{then_animate}{then_post_script}{after_script}
}}""".format(
id=plotdivid,
data=jdata,
Expand All @@ -246,6 +260,7 @@ def to_html(
then_addframes=then_addframes,
then_animate=then_animate,
then_post_script=then_post_script,
after_script=after_script
)

# ## Handle loading/initializing plotly.js ##
Expand All @@ -263,8 +278,9 @@ def to_html(
# Init plotlyjs. This block needs to run before plotly.js is loaded in
# order for MathJax configuration to work properly
if include_plotlyjs == "require":
require_start = 'require(["plotly"], function(Plotly) {'
require_end = "});"
# MODE MODIFIED #
require_start = ''
require_end = ''

elif include_plotlyjs == "cdn":
load_plotlyjs = """\
Expand Down Expand Up @@ -333,13 +349,23 @@ def to_html(
Invalid value of type {typ} received as the include_mathjax argument
Received value: {val}

include_mathjax may be specified as False, 'cdn', or a string ending with '.js'
include_mathjax may be specified as False, 'cdn', or a string ending with '.js'
""".format(
typ=type(include_mathjax), val=repr(include_mathjax)
)
)

# MODE ADDITION #
before_script = """
if (!window["MODE_PYTHON_EMBED"]) {{
document.getElementById("{id}").style.height = "336px";
}}
""".format(id=plotdivid)

# MODE MODIFIED #
plotly_html_div = """\
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>\
<style>.js-plotly-plot .plotly .modebar-group: last-child{{margin-right: 8px}} </style>\
<div>
{mathjax_script}
{load_plotlyjs}
Expand All @@ -348,7 +374,7 @@ def to_html(
<script type="text/javascript">
{require_start}
window.PLOTLYENV=window.PLOTLYENV || {{}};{base_url_line}
{script};
{before_script}{script};
{require_end}
</script>
</div>""".format(
Expand All @@ -361,6 +387,7 @@ def to_html(
require_start=require_start,
script=script,
require_end=require_end,
before_script=before_script,
)

if full_html:
Expand Down
6 changes: 6 additions & 0 deletions packages/python/plotly/plotly/offline/offline.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ def _get_jconfig(config=None):
)

clean_config = config

# MODE ADDITION #
clean_config['showLink'] = False
clean_config['displaylogo'] = False
clean_config['modeBarButtonsToRemove'] = ['sendDataToCloud']

else:
clean_config = {}

Expand Down
6 changes: 3 additions & 3 deletions packages/python/plotly/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,13 +432,13 @@ def run(self):

versioneer_cmds = versioneer.get_cmdclass()
setup(
name="plotly",
name="mode-plotly",
version=versioneer.get_version(),
use_2to3=False,
author="Chris P",
author_email="chris@plot.ly",
maintainer="Jon Mease",
maintainer_email="jon@plot.ly",
maintainer="Mode Analytics",
maintainer_email="support@modeanalytics.com",
url="https://plot.ly/python/",
project_urls={"Github": "https://github.com/plotly/plotly.py"},
description="An open-source, interactive graphing library for Python",
Expand Down