Skip to content

Instantly share code, notes, and snippets.

@neo01124
Last active July 11, 2021 17:54
Show Gist options
  • Save neo01124/449bc7df9f25c6ef055c7efbd2d89a3a to your computer and use it in GitHub Desktop.
Save neo01124/449bc7df9f25c6ef055c7efbd2d89a3a to your computer and use it in GitHub Desktop.
Remove "Export to plotly" link when using plotly and cufflink

Situation

  • You are using plotting Plotly interactive charts through (Cufflinks)[https://github.com/santosjorge/cufflinks] in a Jupyter notebook.
  • Your charts have a link in the bottom right corner - "Export to plotly"
  • You want to remove this from your exported html

Fix

  • Add a raw code cell

  • Paste the following

<script>
  $( document ).ready(function(){
    setTimeout(function(){$("a.link--impt").attr("display","none");}, 500);
  });
</script>
  • Export your notebook as html and load it in the browser. The link should not be displayed.

How it works

  • The raw code cell allows you to add javascript in the notebook which will run in the browser when the notebook is exported as html.
  • <script> denotes javascript
  • $ refers to the Jquery library
  • The "Export to plotly" link is < a > element inside an SVG (the interactive chart) and needs .attr("display","none") to make it not display. Instead, if you wanted to remove a normal html tag you'd use .hide() - $("div.someClass").hide().
  • The SVG charts take some time to render even after the document is ready, setTimeout calls the code to hide the < a > 500ms after the document is ready. You may need to increase this value if your charts take longer to load.

This is a hacky fix needed mainly because Cufflinks doesn't pass 'config' to Plotly's iplot method.

@Rahulvks
Copy link

Rahulvks commented Aug 5, 2020

I need to remove in Jupiter notebook itself is there any other way?

@neo01124
Copy link
Author

Hey @Rahulvks

Don't think there's a way to do that. Maybe an email to plotly support could help.

@Abhijit81
Copy link

I tried the method a couple of times, it isn't working. Inside notebook it says invalid syntax, When i convert to html through nbconverter and open the new html file, i just see the python error and the same old 'export to plotly' link as it would be. It would be awesome if you can suggest further

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment