diff --git a/README.md b/README.md index b5f9274e471..d2aa3e817e5 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,40 @@ +--- + +## 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"` @@ -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" diff --git a/packages/javascript/plotlywidget/package-lock.json b/packages/javascript/plotlywidget/package-lock.json index 18893e6d22f..47eb8559757 100644 --- a/packages/javascript/plotlywidget/package-lock.json +++ b/packages/javascript/plotlywidget/package-lock.json @@ -2188,7 +2188,8 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "aproba": { "version": "1.1.1", @@ -2239,7 +2240,8 @@ "balanced-match": { "version": "0.4.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "bcrypt-pbkdf": { "version": "1.0.1", @@ -2254,6 +2256,7 @@ "version": "0.0.9", "bundled": true, "dev": true, + "optional": true, "requires": { "inherits": "~2.0.0" } @@ -2262,6 +2265,7 @@ "version": "2.10.1", "bundled": true, "dev": true, + "optional": true, "requires": { "hoek": "2.x.x" } @@ -2270,6 +2274,7 @@ "version": "1.1.7", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^0.4.1", "concat-map": "0.0.1" @@ -2278,7 +2283,8 @@ "buffer-shims": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "caseless": { "version": "0.12.0", @@ -2295,12 +2301,14 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "combined-stream": { "version": "1.0.5", "bundled": true, "dev": true, + "optional": true, "requires": { "delayed-stream": "~1.0.0" } @@ -2308,22 +2316,26 @@ "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "cryptiles": { "version": "2.0.5", "bundled": true, "dev": true, + "optional": true, "requires": { "boom": "2.x.x" } @@ -2363,7 +2375,8 @@ "delayed-stream": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "delegates": { "version": "1.0.0", @@ -2395,7 +2408,8 @@ "extsprintf": { "version": "1.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "forever-agent": { "version": "0.6.1", @@ -2417,12 +2431,14 @@ "fs.realpath": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "fstream": { "version": "1.0.11", "bundled": true, "dev": true, + "optional": true, "requires": { "graceful-fs": "^4.1.2", "inherits": "~2.0.0", @@ -2478,6 +2494,7 @@ "version": "7.1.2", "bundled": true, "dev": true, + "optional": true, "requires": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", @@ -2490,7 +2507,8 @@ "graceful-fs": { "version": "4.1.11", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "har-schema": { "version": "1.0.5", @@ -2518,6 +2536,7 @@ "version": "3.1.3", "bundled": true, "dev": true, + "optional": true, "requires": { "boom": "2.x.x", "cryptiles": "2.x.x", @@ -2528,7 +2547,8 @@ "hoek": { "version": "2.16.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "http-signature": { "version": "1.1.1", @@ -2545,6 +2565,7 @@ "version": "1.0.6", "bundled": true, "dev": true, + "optional": true, "requires": { "once": "^1.3.0", "wrappy": "1" @@ -2553,7 +2574,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.4", @@ -2565,6 +2587,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -2578,7 +2601,8 @@ "isarray": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "isstream": { "version": "0.1.2", @@ -2651,12 +2675,14 @@ "mime-db": { "version": "1.27.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "mime-types": { "version": "2.1.15", "bundled": true, "dev": true, + "optional": true, "requires": { "mime-db": "~1.27.0" } @@ -2665,6 +2691,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -2672,12 +2699,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "mkdirp": { "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -2732,7 +2761,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "oauth-sign": { "version": "0.8.2", @@ -2750,6 +2780,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -2779,7 +2810,8 @@ "path-is-absolute": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "performance-now": { "version": "0.2.0", @@ -2790,7 +2822,8 @@ "process-nextick-args": { "version": "1.0.7", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "punycode": { "version": "1.4.1", @@ -2828,6 +2861,7 @@ "version": "2.2.9", "bundled": true, "dev": true, + "optional": true, "requires": { "buffer-shims": "~1.0.0", "core-util-is": "~1.0.0", @@ -2872,6 +2906,7 @@ "version": "2.6.1", "bundled": true, "dev": true, + "optional": true, "requires": { "glob": "^7.0.5" } @@ -2879,7 +2914,8 @@ "safe-buffer": { "version": "5.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "semver": { "version": "5.3.0", @@ -2903,6 +2939,7 @@ "version": "1.0.9", "bundled": true, "dev": true, + "optional": true, "requires": { "hoek": "2.x.x" } @@ -2936,6 +2973,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -2946,6 +2984,7 @@ "version": "1.0.1", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.0.1" } @@ -2960,6 +2999,7 @@ "version": "3.0.1", "bundled": true, "dev": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -2974,6 +3014,7 @@ "version": "2.2.1", "bundled": true, "dev": true, + "optional": true, "requires": { "block-stream": "*", "fstream": "^1.0.2", @@ -3029,7 +3070,8 @@ "util-deprecate": { "version": "1.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "uuid": { "version": "3.0.1", @@ -3058,7 +3100,8 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true } } }, diff --git a/packages/python/chart-studio/chart_studio/tools.py b/packages/python/chart-studio/chart_studio/tools.py index 87b23546b33..5cc32dfed8d 100644 --- a/packages/python/chart-studio/chart_studio/tools.py +++ b/packages/python/chart-studio/chart_studio/tools.py @@ -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 ### diff --git a/packages/python/plotly/plotly/io/_html.py b/packages/python/plotly/plotly/io/_html.py index f2f4aba0ef1..fb5e953952b 100644 --- a/packages/python/plotly/plotly/io/_html.py +++ b/packages/python/plotly/plotly/io/_html.py @@ -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 ) @@ -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, @@ -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 ## @@ -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 = """\ @@ -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 = """\ +\ +\