How To Connect A Jupyter Notebook To Tableau Using Jupytab

Author: Mayank Tiwari


Introduction

This implementation of connecting jupyter notebook to tableau helps us in applications like when we want to display real time data on our dashboards or if you want dynamic predictions based on your ML model you will be able to do that without any hassle.


Prerequisites

For this implementation all you need is having knowledge about the Virtual environment in python , even though i have listed all steps to activate new environments a basic understanding about them will surely help you.


Implementation:

Step 1:


You need to have the Jupyter Notebook on your machine installed first.


Install Jupyter Notebook


Step 2:


Create a virtual environment jupyter-notebook-env


You can use Conda Virtual Environment or with Venv ,whatever suits your need


1) Create Environment


For Venv – python -m venv jupyter-notebook-env



2) Activate Virtual environment


For venv -

by going into folder Scripts of virtual environment

path= \jupyter-server-env\Scripts\activate




For conda env - Conda activate jupyter-notebook-env


Once your Virtual environment is activated


then run


pip install jupytab


pip install ipykernel


then create a kernel


python -m ipykernel install --user --name jupytab-simulation-demo


After installing the kernel select this kernel in the jupyter notebook.


Step 3:


Do Write the Notebook step by referring to the documentation


Jupytab Documentation


Here is a demo:



Note:


When Tableau needs to retrieve the schema of all the available tables, Jupytab executes the (mandatory) cell that starts with # GET /schema:


When Tableau needs to retrieve the data from the tables, Jupytab executes the (mandatory) cell that starts with # GET /data:


Step 4:


Now you have to create another virtual environment named as jupytab-server-env


1) Install jupytab-server


For Venv – pip install jupytab-server


For Conda – conda install jupytab-server=0.9.11


2) Create a config.ini file in the directory where this environment exists


paste this


[main]

listen_port = 8123

notebooks = JupytabSimulator

[JupytabSimulator]

path =/Programs/Python/Python310/Scripts/<jupytab-simulation-notebook>.ipynb


the path to your ipynb file in step 3


Step 5:


Run jupytab --config=<path of config file> or locate into that folder


if you face any error like



Locate to init.py file -> Edit with Notepad++ ->


Include this in top of file


from collections.abc import Mapping,MutableMapping


Then again run error will be resolved and you will get


http://DESKTOP-RVE247D:8123


Note this


Step 6:


Now go to Tableau and in data source


1) Go to Data->New Data Source



2) And then web data connector



3) And type above location and your connection will establish and you will see jupytab simulator as one of the data sources.



The url you see above is all we need to type in web data connector url



Click on Explore in Tableau you will see the dataset in Tableau then



Now you create a dashboard directly using this dataset.


Conclusion

This was all about how to connect these two and there is no limit what you can achieve using this.You can do all computations required on the data on Jupyter Notebook side and you can create dashboards from it.


References

1)Jupytab Documentation

2) Simulation with Tableau and Jupytab




61 views0 comments

Recent Posts

See All