Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save matteoferla/9f88a2dba60b16d65691dfa1e7977083 to your computer and use it in GitHub Desktop.
Save matteoferla/9f88a2dba60b16d65691dfa1e7977083 to your computer and use it in GitHub Desktop.
output plotly HTML to cell for copy pasting
%%javascript
//remember to append <script src="https://cdn.plot.ly/plotly-1.2.0.min.js"></script> to head or top of body.
//output_subarea output_html rendered_html
let index = 0; //or whatever is the number of the graph.
//$('.plotly-graph-div').map((i,el) => element.append('<p>'+$(el).attr('id')+'</p>'))
let chart = $('.plotly-graph-div').eq(index).parent();
/// optionally one could change the dimensions for the .plotly-graph-div and svg elements.
//chart.children('.plotly-graph-div').css('height','525px');
//chart.children('.plotly-graph-div').css('width','100%');
let codeEl = $('<pre id="plotText"><code></code></pre>');
let code = chart
.html()
.replace('\n});<\/script>','</script>')
.replace('require(["plotly"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {};window.PLOTLYENV.BASE_URL="https://plot.ly";','');
// .replace(/\>\</gm,'>\n<');
codeEl.children('code').text(code);
element.html(codeEl);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment