{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# How to share with chart studio\n\nThis tutorial explains how to share plots using chart studio. This \nmethod that was used to share plots on the WordPress blog-post:\n`Improved Deep Learning Workflows Through Hyperparameter Optimization with Or\u00edon\n<https://mila.quebec/en/article/improved-deep-learning-workflows-through-hyperparameter-optimization-with-orion/>`_.\n\n## Uploading to Chart Studio\n\nIf you do not already have a Chart Studio, you can create a \n`free one <https://plotly.com/api_signup>`_. \nWith your account set up, you can get your `API key <https://plotly.com/settings/api>`_\nset Chart Studio's credentials. \n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import chart_studio\n\nusername = \"<your username>\"\napi_key = \"<your api_key>\"\n\nchart_studio.tools.set_credentials_file(username=username, api_key=api_key)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "This will create a credential file locally that will be used in next step.\nNext you can create a ``figure`` and save it to Chart Studio.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# # Push your visualiztion to your account using the following lines of code:\nfrom orion.client import get_experiment\n\n# Specify the database where the experiments are stored. We use a local PickleDB here.\nstorage = dict(type=\"legacy\", database=dict(type=\"pickleddb\", host=\"../../db.pkl\"))\n\nfig = experiment.plot.regret()\n\n\nimport chart_studio.plotly as py\n\npy.plot(fig, filename=\"regret\")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "The plot will be saved under the name ``regret`` in your\n`Chart Studio profile <https://chart-studio.plotly.com/organize/home>`_.\nHere is one example that was used in the blog-post mentioned earlier:\n`https://chart-studio.plotly.com/~xavier.bouthillier/1 <https://chart-studio.plotly.com/~xavier.bouthillier/1>`_.\n\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Sharing on WordPress\n\nSaving HTML version of plots\ndoes not work well with WordPress because it includes JavaScript.\nUsing Chart Studio makes it possible to embed extarnal URL in WordPress posts.\n\nWith Chart Studio,\nyou can get an sharing URL for an embedded plot. In the Viewer page of Chart Studio,\nclick on `export` and then `Embed URL`. This should bring you to a page with an URL\nformatted as ``https://chart-studio.plotly.com/~<your username>/<plot id>.embed``.\n\nWith the `WordPress plugin iframe <https://fr.wordpress.org/plugins/iframe/>`_, you\ncan embed your plot in a blog post. For example, the first plot in\nour blog-post is embedded with the following snippet.\n\n::\n\n    [iframe src=\"//plotly.com/~xavier.bouthillier/1.embed?link=false&amp;autosize=true&amp;height=350\"]\n\nArguments to customized the embedded are documented\n`here\n<https://plotly.com/chart-studio-help/embed-graphs-in-websites/#step-8-customize-the-iframe>`_.\nSee `starting guide <https://plotly.com/python/getting-started-with-chart-studio/>`_\nfor more information on Chart Studio.\n\n"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.7.9"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}