Tableau viz embedded in IPython notebook

时间:2016-04-15 10:59:48

标签: ipython tableau jupyter-notebook tableau-public

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 ?

3 个答案:

答案 0 :(得分:2)

如果您希望Tableau viz显示在Jupyter笔记本中,请在正常单元格中使用%% HTML magic:

%%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>

这是一个很好的资源,你可以用魔法做什么:https://blog.dominodatalab.com/lesser-known-ways-of-using-notebooks/

答案 1 :(得分:0)

基本上你需要做的就是这个

步骤1)从Tableau工作簿中复制java脚本标记

Axiomatics Policy Server AMI

步骤2)转到你的jupyter单元格代码中添加代码,如下所示

enter image description here

答案 2 :(得分:0)

与R和Python相比,Tableau是一种更快速的数据可视化方式。我可以提出的最佳做法是在tableau中创建将大小设置为自动,在Tableau Public上共享它,并在发布后将嵌入代码如下所示。

%%HTML
<Embed Code Here>

在这里查看示例: https://www.kaggle.com/andyxie/tableau-sharing-best-practice/