alexarchambault / plotly-scala

Scala bindings for plotly.js
http://plotly-scala.org
222 stars 48 forks source link

Support for colaboratory #77

Open langley opened 5 years ago

langley commented 5 years ago

I tried uploading the plotly-scala.ipynb from almond.sh examples to colaboratory.

I got it to run but I don't get any plots in the browser.

I've seen some comments about something similar for python in SO.

langley commented 5 years ago

Found out that if I add this to a cell plotly renders!

    kernel.publish.html("""
       <script src="/static/components/requirejs/require.js"></script>
       <script>
         requirejs.config({
            paths: {
            base: '/static/base',
            plotly: 'https://cdn.plot.ly/plotly-latest.min.js?noext',
              },
         });
       </script>""")

Now... on to figuring out how to make this easy or automatic!

This SO article talks about registering pre_run_cell logic for the python solution to the problem.
IPython.get_ipython().events.register('pre_run_cell', configure_plotly_browser_state)

sbrunk commented 5 years ago

The almond module actually does something similar to inject plotly.js into Jupyter classic:

https://github.com/alexarchambault/plotly-scala/blob/52f36e3a1bd3b92c1592d6381966d2741b6e5c7d/almond/src/main/scala/plotly/Almond.scala#L28-L41

If we're able to detect that we're running on colab somehow, we could adapt that logic.