emacs-jupyter / jupyter

An interface to communicate with Jupyter kernels.
GNU General Public License v3.0
917 stars 89 forks source link

Extra example block in html wrapping #265

Open seblemaguer opened 4 years ago

seblemaguer commented 4 years ago

Hello,

I am facing a problem a little bit similar to #157 but with different premisses. I have this org-mode file with the results embedded:


* Import
#+BEGIN_SRC jupyter-python :session test_plotly
  import plotly.express as px
  from plotly.graph_objs import *
  import plotly.offline as py
#+END_SRC

#+results:

* Generate figure
#+name: figure-NSIM
#+BEGIN_SRC jupyter-python :session test_plotly :exports both :results html
  df = px.data.tips()
  fig = px.scatter(df, x="total_bill", y="tip", color="smoker", facet_col="sex")

  # Update layout
  layout = Layout(
      paper_bgcolor='rgba(0,0,0,0)',
      plot_bgcolor='rgba(0,0,0,0)'
  )
  fig.update_layout(layout,
                    legend_orientation="h")

  # Generate div plot
  fig_div = py.plot(
      fig,
      image_width='100%',
      image_height='100%',
      include_plotlyjs=False,
      output_type='div',
      auto_open=False,
  )

  print(fig_div)
#+END_SRC

#+results: figure-NSIM
#+begin_export html
,#+begin_example
  <div>

              <div id="8e816117-a0a6-4034-aa24-e554831d9774" class="plotly-graph-div" style="height:100%; width:100%;"></div>
              <script type="text/javascript">

                      window.PLOTLYENV=window.PLOTLYENV || {};

                  if (document.getElementById("8e816117-a0a6-4034-aa24-e554831d9774")) {
                      Plotly.newPlot(
                          '8e816117-a0a6-4034-aa24-e554831d9774',
                          [{"hovertemplate": "smoker=No<br>sex=Female<br>total_bill=%{x}<br>tip=%{y}<extra></extra>", "legendgroup": "No", "marker": {"color": "#636efa", "symbol": "circle"}, "mode": "markers", "name": "No", "showlegend": true, "type": "scatter", "x": [16.99, 24.59, 35.26, 14.83, 10.33, 16.97, 20.29, 15.77, 19.65, 15.06, 20.69, 16.93, 10.29, 34.81, 26.41, 16.45, 17.07, 14.73, 10.07, 34.83, 22.75, 20.92, 7.25, 25.71, 17.31, 10.65, 12.43, 24.08, 13.42, 12.48, 29.8, 14.52, 11.38, 20.27, 11.17, 12.26, 18.26, 8.51, 10.33, 14.15, 13.16, 17.47, 27.05, 16.43, 8.35, 18.64, 11.87, 29.85, 25.0, 13.39, 16.21, 15.98, 35.83, 18.78], "xaxis": "x", "y": [1.01, 3.61, 5.0, 3.02, 1.67, 3.5, 2.75, 2.23, 3.0, 3.0, 2.45, 3.07, 2.6, 5.2, 1.5, 2.47, 3.0, 2.2, 1.83, 5.17, 3.25, 4.08, 1.0, 4.0, 3.5, 1.5, 1.8, 2.92, 1.68, 2.52, 4.2, 2.0, 2.0, 2.83, 1.5, 2.0, 3.25, 1.25, 2.0, 2.0, 2.75, 3.5, 5.0, 2.3, 1.5, 1.36, 1.63, 5.14, 3.75, 2.61, 2.0, 3.0, 4.67, 3.0], "yaxis": "y"}, {"hovertemplate": "smoker=No<br>sex=Male<br>total_bill=%{x}<br>tip=%{y}<extra></extra>", "legendgroup": "No", "marker": {"color": "#636efa", "symbol": "circle"}, "mode": "markers", "name": "No", "showlegend": false, "type": "scatter", "x": [10.34, 21.01, 23.68, 25.29, 8.77, 26.88, 15.04, 14.78, 10.27, 15.42, 18.43, 21.58, 16.29, 20.65, 17.92, 39.42, 19.82, 17.81, 13.37, 12.69, 21.7, 9.55, 18.35, 17.78, 24.06, 16.31, 18.69, 31.27, 16.04, 17.46, 13.94, 9.68, 30.4, 18.29, 22.23, 32.4, 28.55, 18.04, 12.54, 9.94, 25.56, 19.49, 48.27, 17.59, 20.08, 20.23, 12.02, 10.51, 27.2, 22.76, 17.29, 16.66, 15.98, 13.03, 18.28, 24.71, 21.16, 22.49, 12.46, 18.24, 14.0, 38.07, 23.95, 29.93, 11.69, 14.26, 15.95, 8.52, 22.82, 19.08, 34.3, 41.19, 9.78, 7.51, 14.07, 13.13, 17.26, 24.55, 19.77, 48.17, 16.49, 21.5, 12.66, 13.81, 24.52, 20.76, 31.71, 20.69, 7.56, 48.33, 20.45, 13.28, 11.61, 10.77, 10.07, 29.03, 17.82], "xaxis": "x2", "y": [1.66, 3.5, 3.31, 4.71, 2.0, 3.12, 1.96, 3.23, 1.71, 1.57, 3.0, 3.92, 3.71, 3.35, 4.08, 7.58, 3.18, 2.34, 2.0, 2.0, 4.3, 1.45, 2.5, 3.27, 3.6, 2.0, 2.31, 5.0, 2.24, 2.54, 3.06, 1.32, 5.6, 3.0, 5.0, 6.0, 2.05, 3.0, 2.5, 1.56, 4.34, 3.51, 6.73, 2.64, 3.15, 2.01, 1.97, 1.25, 4.0, 3.0, 2.71, 3.4, 2.03, 2.0, 4.0, 5.85, 3.0, 3.5, 1.5, 3.76, 3.0, 4.0, 2.55, 5.07, 2.31, 2.5, 2.0, 1.48, 2.18, 1.5, 6.7, 5.0, 1.73, 2.0, 2.5, 2.0, 2.74, 2.0, 2.0, 5.0, 2.0, 3.5, 2.5, 2.0, 3.48, 2.24, 4.5, 5.0, 1.44, 9.0, 3.0, 2.72, 3.39, 1.47, 1.25, 5.92, 1.75], "yaxis": "y2"}, {"hovertemplate": "smoker=Yes<br>sex=Female<br>total_bill=%{x}<br>tip=%{y}<extra></extra>", "legendgroup": "Yes", "marker": {"color": "#EF553B", "symbol": "circle"}, "mode": "markers", "name": "Yes", "showlegend": true, "type": "scatter", "x": [3.07, 26.86, 25.28, 5.75, 16.32, 11.35, 15.38, 44.3, 22.42, 14.31, 17.51, 10.59, 10.63, 9.6, 20.9, 18.15, 19.81, 43.11, 13.0, 12.74, 13.0, 16.4, 16.47, 12.76, 13.27, 28.17, 12.9, 30.14, 13.42, 16.27, 10.09, 22.12, 27.18], "xaxis": "x", "y": [1.0, 3.14, 5.0, 1.0, 4.3, 2.5, 3.0, 2.5, 3.48, 4.0, 3.0, 1.61, 2.0, 4.0, 3.5, 3.5, 4.19, 5.0, 2.0, 2.01, 2.0, 2.5, 3.23, 2.23, 2.5, 6.5, 1.1, 3.09, 3.48, 2.5, 2.0, 2.88, 2.0], "yaxis": "y"}, {"hovertemplate": "smoker=Yes<br>sex=Male<br>total_bill=%{x}<br>tip=%{y}<extra></extra>", "legendgroup": "Yes", "marker": {"color": "#EF553B", "symbol": "circle"}, "mode": "markers", "name": "Yes", "showlegend": false, "type": "scatter", "x": [38.01, 11.24, 20.29, 13.81, 11.02, 18.29, 15.01, 17.92, 19.44, 32.68, 28.97, 40.17, 27.28, 12.03, 21.01, 15.36, 20.49, 25.21, 16.0, 50.81, 15.81, 7.25, 31.85, 16.82, 32.9, 17.89, 14.48, 34.63, 34.65, 23.33, 45.35, 23.17, 40.55, 30.46, 23.1, 15.69, 28.44, 15.48, 16.58, 10.34, 13.51, 18.71, 20.53, 26.59, 38.73, 24.27, 30.06, 25.89, 28.15, 11.59, 7.74, 12.16, 8.58, 13.42, 24.01, 15.69, 15.53, 12.6, 32.83, 22.67], "xaxis": "x2", "y": [3.0, 1.76, 3.21, 2.0, 1.98, 3.76, 2.09, 3.08, 3.0, 5.0, 3.0, 4.73, 4.0, 1.5, 3.0, 1.64, 4.06, 4.29, 2.0, 10.0, 3.16, 5.15, 3.18, 4.0, 3.11, 2.0, 2.0, 3.55, 3.68, 5.65, 3.5, 6.5, 3.0, 2.0, 4.0, 1.5, 2.56, 2.02, 4.0, 2.0, 2.0, 4.0, 4.0, 3.41, 3.0, 2.03, 2.0, 5.16, 3.0, 1.5, 1.44, 2.2, 1.92, 1.58, 2.0, 3.0, 3.0, 1.0, 1.17, 2.0], "yaxis": "y2"}],
                          {"annotations": [{"showarrow": false, "text": "sex=Female", "x": 0.245, "xanchor": "center", "xref": "paper", "y": 1.0, "yanchor": "bottom", "yref": "paper"}, {"showarrow": false, "text": "sex=Male", "x": 0.755, "xanchor": "center", "xref": "paper", "y": 1.0, "yanchor": "bottom", "yref": "paper"}], "legend": {"orientation": "h", "title": {"text": "smoker"}, "tracegroupgap": 0}, "margin": {"t": 60}, "paper_bgcolor": "rgba(0,0,0,0)", "plot_bgcolor": "rgba(0,0,0,0)", "template": {"data": {"bar": [{"error_x": {"color": "#2a3f5f"}, "error_y": {"color": "#2a3f5f"}, "marker": {"line": {"color": "#E5ECF6", "width": 0.5}}, "type": "bar"}], "barpolar": [{"marker": {"line": {"color": "#E5ECF6", "width": 0.5}}, "type": "barpolar"}], "carpet": [{"aaxis": {"endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f"}, "baxis": {"endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f"}, "type": "carpet"}], "choropleth": [{"colorbar": {"outlinewidth": 0, "ticks": ""}, "type": "choropleth"}], "contour": [{"colorbar": {"outlinewidth": 0, "ticks": ""}, "colorscale": [[0.0, "#0d0887"], [0.1111111111111111, "#46039f"], [0.2222222222222222, "#7201a8"], [0.3333333333333333, "#9c179e"], [0.4444444444444444, "#bd3786"], [0.5555555555555556, "#d8576b"], [0.6666666666666666, "#ed7953"], [0.7777777777777778, "#fb9f3a"], [0.8888888888888888, "#fdca26"], [1.0, "#f0f921"]], "type": "contour"}], "contourcarpet": [{"colorbar": {"outlinewidth": 0, "ticks": ""}, "type": "contourcarpet"}], "heatmap": [{"colorbar": {"outlinewidth": 0, "ticks": ""}, "colorscale": [[0.0, "#0d0887"], [0.1111111111111111, "#46039f"], [0.2222222222222222, "#7201a8"], [0.3333333333333333, "#9c179e"], [0.4444444444444444, "#bd3786"], [0.5555555555555556, "#d8576b"], [0.6666666666666666, "#ed7953"], [0.7777777777777778, "#fb9f3a"], [0.8888888888888888, "#fdca26"], [1.0, "#f0f921"]], "type": "heatmap"}], "heatmapgl": [{"colorbar": {"outlinewidth": 0, "ticks": ""}, "colorscale": [[0.0, "#0d0887"], [0.1111111111111111, "#46039f"], [0.2222222222222222, "#7201a8"], [0.3333333333333333, "#9c179e"], [0.4444444444444444, "#bd3786"], [0.5555555555555556, "#d8576b"], [0.6666666666666666, "#ed7953"], [0.7777777777777778, "#fb9f3a"], [0.8888888888888888, "#fdca26"], [1.0, "#f0f921"]], "type": "heatmapgl"}], "histogram": [{"marker": {"colorbar": {"outlinewidth": 0, "ticks": ""}}, "type": "histogram"}], "histogram2d": [{"colorbar": {"outlinewidth": 0, "ticks": ""}, "colorscale": [[0.0, "#0d0887"], [0.1111111111111111, "#46039f"], [0.2222222222222222, "#7201a8"], [0.3333333333333333, "#9c179e"], [0.4444444444444444, "#bd3786"], [0.5555555555555556, "#d8576b"], [0.6666666666666666, "#ed7953"], [0.7777777777777778, "#fb9f3a"], [0.8888888888888888, "#fdca26"], [1.0, "#f0f921"]], "type": "histogram2d"}], "histogram2dcontour": [{"colorbar": {"outlinewidth": 0, "ticks": ""}, "colorscale": [[0.0, "#0d0887"], [0.1111111111111111, "#46039f"], [0.2222222222222222, "#7201a8"], [0.3333333333333333, "#9c179e"], [0.4444444444444444, "#bd3786"], [0.5555555555555556, "#d8576b"], [0.6666666666666666, "#ed7953"], [0.7777777777777778, "#fb9f3a"], [0.8888888888888888, "#fdca26"], [1.0, "#f0f921"]], "type": "histogram2dcontour"}], "mesh3d": [{"colorbar": {"outlinewidth": 0, "ticks": ""}, "type": "mesh3d"}], "parcoords": [{"line": {"colorbar": {"outlinewidth": 0, "ticks": ""}}, "type": "parcoords"}], "pie": [{"automargin": true, "type": "pie"}], "scatter": [{"marker": {"colorbar": {"outlinewidth": 0, "ticks": ""}}, "type": "scatter"}], "scatter3d": [{"line": {"colorbar": {"outlinewidth": 0, "ticks": ""}}, "marker": {"colorbar": {"outlinewidth": 0, "ticks": ""}}, "type": "scatter3d"}], "scattercarpet": [{"marker": {"colorbar": {"outlinewidth": 0, "ticks": ""}}, "type": "scattercarpet"}], "scattergeo": [{"marker": {"colorbar": {"outlinewidth": 0, "ticks": ""}}, "type": "scattergeo"}], "scattergl": [{"marker": {"colorbar": {"outlinewidth": 0, "ticks": ""}}, "type": "scattergl"}], "scattermapbox": [{"marker": {"colorbar": {"outlinewidth": 0, "ticks": ""}}, "type": "scattermapbox"}], "scatterpolar": [{"marker": {"colorbar": {"outlinewidth": 0, "ticks": ""}}, "type": "scatterpolar"}], "scatterpolargl": [{"marker": {"colorbar": {"outlinewidth": 0, "ticks": ""}}, "type": "scatterpolargl"}], "scatterternary": [{"marker": {"colorbar": {"outlinewidth": 0, "ticks": ""}}, "type": "scatterternary"}], "surface": [{"colorbar": {"outlinewidth": 0, "ticks": ""}, "colorscale": [[0.0, "#0d0887"], [0.1111111111111111, "#46039f"], [0.2222222222222222, "#7201a8"], [0.3333333333333333, "#9c179e"], [0.4444444444444444, "#bd3786"], [0.5555555555555556, "#d8576b"], [0.6666666666666666, "#ed7953"], [0.7777777777777778, "#fb9f3a"], [0.8888888888888888, "#fdca26"], [1.0, "#f0f921"]], "type": "surface"}], "table": [{"cells": {"fill": {"color": "#EBF0F8"}, "line": {"color": "white"}}, "header": {"fill": {"color": "#C8D4E3"}, "line": {"color": "white"}}, "type": "table"}]}, "layout": {"annotationdefaults": {"arrowcolor": "#2a3f5f", "arrowhead": 0, "arrowwidth": 1}, "coloraxis": {"colorbar": {"outlinewidth": 0, "ticks": ""}}, "colorscale": {"diverging": [[0, "#8e0152"], [0.1, "#c51b7d"], [0.2, "#de77ae"], [0.3, "#f1b6da"], [0.4, "#fde0ef"], [0.5, "#f7f7f7"], [0.6, "#e6f5d0"], [0.7, "#b8e186"], [0.8, "#7fbc41"], [0.9, "#4d9221"], [1, "#276419"]], "sequential": [[0.0, "#0d0887"], [0.1111111111111111, "#46039f"], [0.2222222222222222, "#7201a8"], [0.3333333333333333, "#9c179e"], [0.4444444444444444, "#bd3786"], [0.5555555555555556, "#d8576b"], [0.6666666666666666, "#ed7953"], [0.7777777777777778, "#fb9f3a"], [0.8888888888888888, "#fdca26"], [1.0, "#f0f921"]], "sequentialminus": [[0.0, "#0d0887"], [0.1111111111111111, "#46039f"], [0.2222222222222222, "#7201a8"], [0.3333333333333333, "#9c179e"], [0.4444444444444444, "#bd3786"], [0.5555555555555556, "#d8576b"], [0.6666666666666666, "#ed7953"], [0.7777777777777778, "#fb9f3a"], [0.8888888888888888, "#fdca26"], [1.0, "#f0f921"]]}, "colorway": ["#636efa", "#EF553B", "#00cc96", "#ab63fa", "#FFA15A", "#19d3f3", "#FF6692", "#B6E880", "#FF97FF", "#FECB52"], "font": {"color": "#2a3f5f"}, "geo": {"bgcolor": "white", "lakecolor": "white", "landcolor": "#E5ECF6", "showlakes": true, "showland": true, "subunitcolor": "white"}, "hoverlabel": {"align": "left"}, "hovermode": "closest", "mapbox": {"style": "light"}, "paper_bgcolor": "white", "plot_bgcolor": "#E5ECF6", "polar": {"angularaxis": {"gridcolor": "white", "linecolor": "white", "ticks": ""}, "bgcolor": "#E5ECF6", "radialaxis": {"gridcolor": "white", "linecolor": "white", "ticks": ""}}, "scene": {"xaxis": {"backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white"}, "yaxis": {"backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white"}, "zaxis": {"backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white"}}, "shapedefaults": {"line": {"color": "#2a3f5f"}}, "ternary": {"aaxis": {"gridcolor": "white", "linecolor": "white", "ticks": ""}, "baxis": {"gridcolor": "white", "linecolor": "white", "ticks": ""}, "bgcolor": "#E5ECF6", "caxis": {"gridcolor": "white", "linecolor": "white", "ticks": ""}}, "title": {"x": 0.05}, "xaxis": {"automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": {"standoff": 15}, "zerolinecolor": "white", "zerolinewidth": 2}, "yaxis": {"automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": {"standoff": 15}, "zerolinecolor": "white", "zerolinewidth": 2}}}, "xaxis": {"anchor": "y", "domain": [0.0, 0.49], "title": {"text": "total_bill"}}, "xaxis2": {"anchor": "y2", "domain": [0.51, 1.0], "matches": "x", "title": {"text": "total_bill"}}, "yaxis": {"anchor": "x", "domain": [0.0, 1.0], "title": {"text": "tip"}}, "yaxis2": {"anchor": "x2", "domain": [0.0, 1.0], "matches": "y", "showticklabels": false}},
                          {"responsive": true}
                      )
                  };

              </script>
          </div>
,#+end_example
#+end_export

As you can see, there is an extra example block. Is there any way to get rid of this example block?

Thanks a lot

gmoutso commented 3 years ago

I think the example block is because of the print command. Try to return rich html without print, perhaps with the :pandoc 'nil :display html options. I don't have plotly to try this.

seblemaguer commented 3 years ago

@gmoutso thanks a lot. I try this when I am back home