Tips on how to Combine Google Gemini into Tableau Dashboards?

Introduction

Tableau is a strong and superior visualization software. It covers the entire visible growth lifecycle. Beginning with Tableau Prep Builder, you possibly can successfully clear, remodel, and supply knowledge beneath one roof. Tableau Desktop then presents this knowledge to inform a narrative, whereas Tableau Server means that you can share these visuals with the meant viewers. On this complete course of, the interpretation of the dashboard requires a handbook effort. From the creator’s viewpoint, the dashboard presents an ideal pattern such that it grasps all of the eyeballs however from a viewer’s perspective, it would take a while to grasp the dashboard. The viewer would require a walkthrough of the charts, and figures after which draw some conclusions. To streamline this course of, integrating Google Gemini into Tableau can improve dashboard comprehension by leveraging AI-driven insights, lowering the time required to interpret knowledge.

What if the viewer will get an AI helper to determine the charts and figures themselves? Introducing LLMs. For the reason that introduction of GPTs and massive language fashions (LLMs), many handbook workflows, similar to chatbots, translations, and analysis, have shifted to AI brokers. Knowledge Evaluation is one such sector that’s steadily sliding to AI brokers. These brokers can take up automated knowledge wrangling, anomaly detection, characteristic choice, or predictive analytics. On this information, we are going to discover the best way to combine Google Gemini into Tableau dashboards. Ask it to present knowledge summaries, predictions, conclusions, and extra.

Studying Aims

  • Uncover the best way to increase your dashboard performance with Dashboard Extensions.
  • Perceive the toolkit for organising Gemini in Tableau Dashboards.
  • Discover the best way to leverage Python to work together with the Tableau Dashboard and ship info to and from the dashboards.
  • Learn to allow customers to ask questions on graphs and figures and get responses in the identical window.
  • Acknowledge the potential safety dangers of sending delicate info to LLMs.

This text was printed as part of the Knowledge Science Blogathon.

What are Dashboard Extensions?

Including an exterior service to an already fully-fledged utility is a tough process. Tableau is a pretty big utility and it’s practically unattainable to code out a brand new characteristic with out accessing all of the codebase and the dependencies. Due to this fact we now have Tableau Dashboard Extensions. Dashboard Extensions are internet apps that may be included right into a dashboard like different dashboard parts. These internet apps work together with Tableau internals utilizing Tableau Extensions API. On a excessive degree, these apps will be divided into two sorts:

  • Community-enabled: These apps run on servers situated exterior the Tableau setting. The app will be hosted on any platform and the client-side code is embedded straight into Tableau through the extension file (trex).
  • Sandboxed: The sandboxed apps run in a protected setting with restricted or no entry to sources or internet companies. Often developed by the Tableau workforce, they’ve restricted capabilities but are highly effective in enhancing dashboard interactivity.
How to Integrate Gemini into Tableau Dashboards?

There’s a complete library of Dashboard Extensions out there on the Tableau Change. Some are formally developed by the Tableau and Salesforce groups and extra by well-known companies. The extensions are a good way to increase the performance of a base dashboard and make it extra interactive. There are extensions to export knowledge from the charts, add new info to the dashboards, or edit the present knowledge!

For our use case, we are going to construct a Dashboard extension the place a consumer selects knowledge factors on the dashboard, submits a query, sends all this info to Gemini for evaluation, and shows the ends in the identical window.

Dashboard Extensions makes use of the underlying Tableau Extensions API to work together with the Tableau dashboard’s inner objects. This JavaScript library API can restrict the Python developer’s abilities. To beat this, we are going to use Anvil. Anvil is a platform for constructing full-stack internet functions in Python. It has an open-source library known as trexjacket that enables builders to work together with the dashboard internals utilizing Python. The Anvil sits as an interface between Tableau JavaScript APIs and the Python code from the consumer aspect. The trexjacket supplies the Tableau dashboard entry through Python and the workflow continues.

For our Dashboard Extension that works with Google Gemini, we’d like the next:

  • Gemini API Entry
  • Anvil venture preconfigured with trexjacket
  • Tableau Software and a Dashboard

Gemini API Entry

Google has launched API entry to Gemini, beforehand referred to as Bard beneath a sub-vertical known as “Google AI for builders”. One can discover Gemini API, Google AI Studio, Gemma fashions, and Google AI Edge. The API entry remains to be supplied through the Google Cloud Undertaking (GCP). Head to Gemini and click on the “Get API key in Google Studio” choice. Clicking “Create API key” will immediate two choices, create a brand new venture or add API entry to an current venture. 

Setting up GCP for Gemini API access

Select any choice and maintain the API key in a secure place.

Anvil Undertaking with Trexjacket

Anvil is a powerpack platform providing full-stack internet growth in Python. The principle differentiator is constructing the frontend in Python and successfully stitching it to the backend server code. The design organizes the entire utility in an object-oriented programming paradigm, facilitating simpler entry and administration of various parts within the internet app. It additionally permits modifying the underlying make-up information, HTML, CSS, and JS for extra granular management over the consumer interface. 

Anvil has constructed a template venture preconfigured with trexjacket that fast-tracks the Dashboard extension growth beneath Anvil X. This template has the configuration set for trexjacket as a dependency for the Anvil app. To arrange a venture with trexjacket as a dependency, join an account on anvil.works, choose “Create a brand new app” and choose “Tableau Extension”.

Setting up Anvil for Tableau Extension

Within the template app, you possibly can delete the configure settings, and startup module and clear up the design web page of the app as these usually are not wanted for our use case. Subsequent, we have to add the Google Generative AI Python library within the Anvil setting. For that, go to settings from the left, choose Python variations, change to Python beta, choose the bottom package deal as customary, and add the package deal identify as “google-generativeai”

Adding Google Generative AI library: Integrate Google Gemini into Tableau

For the scope of this information, we won’t discover Anvil fundamentals and canopy solely the required sections of Anvil. If you wish to deep-dive into Anvil as a software, try my different article Frontend, Backend & Database Utilizing Python: Anvil

Tableau

Tableau Dashboard extensions assist each desktop and server/cloud cases, in addition to Tableau Desktop Public and full-suite functions. We are going to use Tableau Desktop Public to check the extension in our use case. The following factor we require is a working dashboard. You’ll be able to decide any dashboard of your selection for testing functions. I’m utilizing a dashboard printed on Tableau Public in regards to the Paris Olympics 2024.

A sample image from Dashboard: Tableau Dashboards

Notice: The creator of this dashboard mentions the dataset is from the Paris 2024 Olympic Video games Dataset in Kaggle.

Tableau Dashboard and Anvil Connection Setup

Let’s create a dummy extension to determine the connection between the Tableau Dashboard and the Anvil. Within the Anvil app, drag a label from the add part choice to show some textual content. Upon clicking this label, we will change the label show textual content and tweak different properties similar to font, coloration, and measurement.

Adding a label to anvil screen: Tableau Dashboards

Subsequent, from the highest of the app, click on “Check in Tableau” and obtain the manifest file. This file has the “trex” extension and will be loaded as a neighborhood extension within the Tableau Dashboard. You’ll be able to select to maintain the dashboard in Tableau Desktop for now and later publish it on the server. The server configuration for that will likely be talked about within the popup. 

Tableau Dashboards

Now drag an extension object into the Tableau dashboard and click on “Entry Native Extensions”. Right here choose the manifest file generated by Anvil.

Tableau Dashboards
Adding dashboard extension

This extension will work together with Anvil to course of the information we ship from the Tableau dashboard and due to this fact falls beneath the network-enabled class of Dashboard extensions. Choose “Okay” when prompted to permit entry to the extension. The Anvil App will load within the window, establishing our connection between the Tableau Dashboard and the Anvil server! We are able to begin including parts to this app and sew the Gemini API.

Extension in dashboard: Tableau Dashboards

Constructing the Extension UI

Anvil supplies drag-and-drop performance for designing the consumer interface of the applying. There are numerous parts out there within the library to select from. For our use case, the design breakdown seems like this:

  • Enter field (TextBox) for taking the consumer query
  • Submit button for sending the information to Anvil and Clear button to clear the query and the evaluation textual content
  • A abstract label placeholder will show textual content that the Gemini API replaces with the outcomes.
  • A title, colours for submit and clear button, and textual content colours to enhance consumer expertise
  • You’ll be able to add the placeholder texts and show names by clicking on the part, opening the properties panel, and modifying the required attributes.

 Under is the design we will likely be utilizing for this extension:

Extension UI

The most effective half about network-enabled extensions is the flexibility to ship adjustments to the top consumer with none reinstallation. We are able to see the up to date UI straight within the dashboard with out regenerating the manifest file. Click on on the extension object, choose the dropdown, and click on “Reload”. It will replace the extension in real-time.

Updating the extension in dashboard

We have to present object names to those UI parts to sew them collectively, change their state within the coding half, and make them useful. To try this, open the part properties panel and add the identify within the “self”. As you possibly can guess, these parts will likely be out there as objects on our foremost display screen. The names supplied for this extension are:

  • TextBox: user_question
  • Submit Button: btn_submit
  • Clear Button: btn_clear
  • Abstract Label: abstract

Coding the Logics for Extension

In Anvil, client-side coding manages the consumer interface and handles all UI interactions, whereas holding much less safe coding parts. For the reason that shopper code runs within the internet browser, it has restricted capabilities for processes on the browser degree. Alternatively, server-side coding manages duties like authentication, password checks, and sustaining database connections.

In our case, the shopper code can deal with all of the dashboard interactions and cross this knowledge to the server code to organize and ship to the Gemini. The Gemini API must be accessed securely and would require server-side coding there. Let’s begin organising the client-side coding after which transfer to the server aspect.

Accessing Dashboard and Stitching UI

To modify to the coding a part of the UI, choose the “Code” tab from the highest. The system populates it with some boilerplate code to get issues began. You’ll be able to take away issues like registering occasion handlers and the config web page at startup for now. Use the code under as a place to begin to comply with alongside.

from ._anvil_designer import client_codeTemplate
from anvil import *
import anvil.server

from trexjacket.api import get_dashboard
dashboard = get_dashboard()

class client_code(client_codeTemplate):
  def __init__(self, **properties):
    self.init_components(**properties)
    

The system routinely imports and initializes the trexjacket as a dashboard object named “dashboard,” which serves because the entry level to entry all of the dashboard interactions. We are able to register 3 sorts of interactions from the dashboard: choice, filter & parameter change. To register an occasion kind, we have to use the register_event_handler perform of the dashboard object. It takes the occasion kind and the handler perform because the arguments. The handler perform takes care of the half when the occasion is triggered. This perform can entry the occasion metadata, worksheet, and underlying knowledge.

In our case, the alternatives accomplished within the dashboard have to move by our extension. Subsequent, to get the chosen knowledge level values, we will use the handler perform’s occasion worksheet object to name the get_selected_marks perform and retailer it to cross the information to the backend. For demonstration, let’s change the show worth of the abstract part to point out the chosen values. To try this, we will modify the textual content property of the part to take the worth as the choice.

Code Implementation

Right here is the code implementation:

class client_code(client_codeTemplate):
  def __init__(self, **properties):
    self.init_components(**properties)
    dashboard.register_event_handler('selection_changed', self.selection_changed_event_handler)
    
  def selection_changed_event_handler(self, occasion):
    user_selections = occasion.worksheet.get_selected_marks()

    if len(user_selections) != 0:
      self._data = user_selections
      self.abstract.textual content = user_selections
Capturing the data points in dashboard extension: Integrate Google Gemini into Tableau

Subsequent, we’d like the Submit and Clear buttons useful. You’ll be able to view the kind of occasions supported for any part by deciding on the part and switching to the properties panel. The occasions part will record all of the occasions together with their perform mappings. For buttons, we have to map the press occasion to do some operations. 

  • Clear button: We have to clear the query field, abstract part, and the information saved for beforehand chosen marks
  • Submit button: The textual content within the query field must be despatched to the Gemini API.

The meant work of the submit button will likely be mentioned within the subsequent part. For now, let’s exchange the abstract textual content with the query textual content upon clicking the submit button.

Code Implementation

The code implementation is as:

class client_code(client_codeTemplate):
  def __init__(self, **properties):
    self.init_components(**properties)
    self.abstract.seen = False
    dashboard.register_event_handler('selection_changed', self.selection_changed_event_handler)

  def selection_changed_event_handler(self, occasion):
    user_selections = occasion.worksheet.get_selected_marks()

    if len(user_selections) != 0:
        self._data = user_selections

  def btn_submit_click(self, **event_args):
    """This technique known as when the button is clicked"""
    self.abstract.seen = True
    self.abstract.textual content = self.user_question.textual content

  def btn_clear_click(self, **event_args):
    """This technique known as when the button is clicked"""
    self.abstract.textual content=""
    self.user_question.textual content=""
    self._data=""
    self.abstract.seen = False
    
Stitching the UI: Integrate Google Gemini into Tableau

Including Gemini API Backend

Our UI is able to settle for the consumer inputs and the parts are stitched collectively. Now we will add the mind of our utility, the Gemini API entry to course of these consumer inputs. The following advice describe our subsequent steps:

  • Server module: So as to add server-side coding to the applying, click on on 3-dots within the server code part on the left and choose “add server module”.
  • Secrets and techniques: We must always retailer the Gemini API entry key in a safe place to forestall unauthorized requests. Anvil Secrets and techniques is a secret supervisor the place we will add keys, passwords, or credentials and entry them in our code utilizing the Anvil secret module.
  • Pre-configure Gemini API: Though Gemini like every other LLM can course of any info, we will present pre-context to Gemini. This context will assist us get extra refined responses and concentrate on our use case. We are able to cross these directions whereas initializing our mannequin object.

The code half for the above rationalization goes like this:

import anvil.secrets and techniques
import google.generativeai as genai

GOOGLE_API_KEY = anvil.secrets and techniques.get_secret("GEMINI_API")
genai.configure(api_key=GOOGLE_API_KEY)
mannequin = genai.GenerativeModel(model_name="gemini-1.5-flash", system_instruction=[
        "You are an expert analyst and know everything about data analysis",
        "You can interpret data in any form whether it's a single data point or a list of data with keys"
        "You are on a mission to provide the best data analysis report when asked",
        "You are capable of answering the question without report as well on topics that require you to answer between a finite set of possibilities",
    ],)

Subsequent, we have to create a perform that accepts the query and the information from the shopper, processes the data, and returns the resultant values. We expose this perform to the client-side code to permit it to make calls. We use the Anvil callable decorator to wrap these capabilities and make them callable from the client-side code.

Remaining Operate in Server Module

Right here is our last perform within the server module:

@anvil.server.callable
def generateDataSummary(immediate, knowledge):
  revised_prompt = f'''
  {immediate} + "nn" + {knowledge}
  '''
  response = mannequin.generate_content(revised_prompt)
  return response.textual content

The final step in constructing our dashboard extension is to name this perform, present the consumer inputs, and show the outcomes returned by Gemini API when the consumer selects some knowledge factors and clicks on the submit button. To realize this, we have to use the anvil server module name perform.This perform takes the perform identify uncovered as callable within the server module and accepts the parameters as key phrase arguments. Moreover, we will add a notification for consumer acknowledgment utilizing the Notification module. This implementation is completed as:

class client_code(client_codeTemplate):
  .
  .
  def btn_submit_click(self, **event_args):
    """This technique known as when the button is clicked"""
    msg = "Wait"
    Notification(msg).present()
    self.abstract.textual content=""
    dataSummary = anvil.server.name('generateDataSummary', immediate=self.user_question.textual content, knowledge=self._data)
    self.abstract.seen = True
    self.abstract.textual content = dataSummary
    self._data=""

Testing out the Extension

Our extension is able to take inputs from dashboards, course of them in Gemini, and return ends in the identical window! Reload the extension within the dashboard, choose some knowledge factors, enter some questions, and hit undergo see the outcomes.

Integrate Google Gemini into Tableau

Take a look at this demo video to see issues in motion:

Potential Safety Dangers

We’ve efficiently created a Tableau Dashboard extension that seamlessly integrates into the dashboard. This extension will be added to any dashboard with none points. The one concern with utilizing an LLM could possibly be the sensitivity of information. Datasets similar to monetary, private well being, confidential, or proprietary info may require extra safety measures and knowledge anonymization/redaction strategies to make sure privateness and compliance. Though LLM supplier firms similar to OpenAI present some flexibility to not permit the information coaching of the mannequin. It would change relying in your agency and one ought to seek the advice of the infosec workforce earlier than implementing such options.  

Conclusion

On this information, we noticed the best way to combine Google Gemini into Tableau Dashboards on a deeper degree. The response high quality depends upon how the query (immediate) is supplied. Many enhancements will be made to the extension similar to including a configuration web page to supply choices for choosing the mannequin for use, updating system directions, preprocessing the information to be despatched, and far more.

On the trexjacket aspect, you possibly can discover different functionalities similar to accessing the filters and parameters or straight accessing the underlying knowledge for a worksheet. The documentation is the very best place to test these capabilities. One can develop extensions natively in JavaScript as nicely however it’s a studying curve for the Python neighborhood, due to this fact, leveraging Anvil. 

Key Takeaways

  • Tableau Extension is a good way to profit from your dashboards. There are tons of extensions for a wide range of use circumstances similar to visualization extensions for including Sankey move charts which aren’t natively supported on the time of writing.
  • One can use Gemini, an LLM, to demo the dashboard extension, but it surely’s additionally attainable to make use of any LLM, a fine-tuned model, or a knowledge specialist LLM for sensible functions.
  • Integrating an LLM in your dashboards can free an analyst from answering among the repetitive queries and focus extra on taking motion.
  • One must also concentrate on the potential knowledge leakage and use such techniques carefully by avoiding passing on delicate info.

Steadily Requested Questions

Q1. What are Tableau Extensions?

A. Tableau Extension is a approach so as to add functionalities to a dashboard that’s not natively shipped in Tableau software program. There are extensions to export knowledge from a dashboard, add checkboxes in parameters, superior date pickers, and far more.

Q2. What’s the position of Anvil and trexjacket?

A. Anvil supplies the platform to construct full-stack internet functions solely utilizing Python. This enables us to create the Tableau Extension UI with out pondering of dealing with the JavaScript. Trexjacket supplies an abstraction over dashboard parts and methods to entry them programmatically.

Q3. Tips on how to add an Extension to a dashboard?

A. Within the dashboard objects, drag the Extension object within the dashboard sheet and it’ll open a popup. Right here you possibly can select from already printed extensions or load your custom-build extension.

This autumn. What are the sorts of interactions that may be captured utilizing trexjacket?

A. Choice, filters, and parameters interactions will be captured utilizing trexjacket

Q5. Can I exploit ChatGPT API as an alternative of Gemini?

A. Sure, so long as you expose the LLM as an API endpoint, you possibly can select any LLM and combine it into your Tableau Dashboards.

Q6. How can I combine Google Gemini into Tableau?

A. You’ll be able to combine Google Gemini into Tableau through the use of API endpoints to reinforce dashboards with AI-driven insights and occasion administration.

The media proven on this article just isn’t owned by Analytics Vidhya and is used on the Creator’s discretion.

Kaustubh Gupta is a talented engineer with a B.Tech in Data Know-how from Maharaja Agrasen Institute of Know-how. With expertise as a CS Analyst and Analyst Intern at Prodigal Applied sciences, Kaustubh excels in Python, SQL, Libraries, and varied engineering instruments. He has developed core parts of product intent engines, created gold tables in Databricks, and constructed inner instruments and dashboards utilizing Streamlit and Tableau. Acknowledged as India’s High 5 Group Contributor 2023 by Analytics Vidhya, Kaustubh can be a prolific author and mentor, contributing considerably to the tech neighborhood by talking classes and workshops.

Leave a Reply

Your email address will not be published. Required fields are marked *