M. Page
M. Page

Reputation: 2814

Tableau viz embedded in IPython notebook

I have published a Tableau 9.3 viz on Tableau public: https://public.tableau.com/profile/michel.page#!/vizhome/exercice1/Courbesventesetprofit

I have succedded to have this viz displayed in a web page by integrating the code given by the 'Share' button on the Tableau public viz page.

Now I want to do the same, but inside an IPython notebook. It seems to be possible because I saw an example in nbviewer here: http://nbviewer.jupyter.org/gist/msund/96bd1d837f4139b2558d

I have integrated the 'Share' button script code into a Markdown cell but the viz won't get displayed when the cell is run. When I look at the browser console, it seems that the js code, and object tag get sanitized, even if I tell IPython to trust the notebook.

Is there any workaround ?

Upvotes: 3

Views: 2929

Answers (3)

Andrew Xie
Andrew Xie

Reputation: 1

Compared with R and Python, Tableau is a much faster way for data visualization. The best practice I can come up with is to set size to automatic when you create in tableau, share it on Tableau Public, and put the embed code like the following after you publish.

%%HTML
<Embed Code Here>

Look for example here: https://www.kaggle.com/andyxie/tableau-sharing-best-practice/

Upvotes: 0

sushmit
sushmit

Reputation: 4603

Basically what you need to do is this

step 1) copy the java script tag from Tableau workbook

enter image description here

step 2) Go and add the code in your jupyter cell code as below

enter image description here

Upvotes: 0

rmdelgad
rmdelgad

Reputation: 96

If you want the Tableau viz to show up in your Jupyter notebook, Use the %%HTML magic in a normal cell:

%%HTML

<div class='tableauPlaceholder' id='viz1474058356757' style='position: relative'><noscript><a href='#'><img alt=' ' src='https:&#47;&#47;public.tableau.com&#47;static&#47;images&#47;ex&#47;exercice1&#47;Courbesventesetprofit&#47;1_rss.png' style='border: none' /></a></noscript><object class='tableauViz'  style='display:none;'><param name='host_url' value='https%3A%2F%2Fpublic.tableau.com%2F' /> <param name='site_root' value='' /><param name='name' value='exercice1&#47;Courbesventesetprofit' /><param name='tabs' value='yes' /><param name='toolbar' value='yes' /><param name='static_image' value='https:&#47;&#47;public.tableau.com&#47;static&#47;images&#47;ex&#47;exercice1&#47;Courbesventesetprofit&#47;1.png' /> <param name='animate_transition' value='yes' /><param name='display_static_image' value='yes' /><param name='display_spinner' value='yes' /><param name='display_overlay' value='yes' /><param name='display_count' value='yes' /></object></div>                <script type='text/javascript'>                    var divElement = document.getElementById('viz1474058356757');                    var vizElement = divElement.getElementsByTagName('object')[0];                    vizElement.style.width='100%';vizElement.style.height=(divElement.offsetWidth*0.75)+'px';                    var scriptElement = document.createElement('script');                    scriptElement.src = 'https://public.tableau.com/javascripts/api/viz_v1.js';                    vizElement.parentNode.insertBefore(scriptElement, vizElement);                </script>

This is a great resource on what else you can do with magics: https://blog.dominodatalab.com/lesser-known-ways-of-using-notebooks/

Upvotes: 3

Related Questions