QBoard » Advanced Visualizations » Viz - Tableau » Scripts or plug-ins for Tableau?

Scripts or plug-ins for Tableau?

  • Can one write plug-ins for Tableau? Is Tableau equipped with any sort of general-purpose scripting language?

    e.g., for generating visualizations that cannot be created using the default Tableau tools, or for doing k-means clustering on a dataset using various metrics, etc...

      December 30, 2020 9:51 AM IST
    1
  • Tableau has several extension points at the moment.

    • If you publish to Tableau Server, On-Line or Public, then you can use Tableau's JavaScript API to interact between your web app client and the Tableau visualization. Your javascript can be notified of events in the Tableau viz, and also effectively command it.
    • Instead of using the JavaScript API, you can include URL query parameters to pass filters, adjust the sizes and control a few other aspects. Similarly, you can append a format string like ".png" or ".pdf" or ".csv" to request a static snapshot in a particular format instead of an interactive object. You can't control as much via the URL as you can via the Javascript API, but the URL approach is very simple and easy for common cases.

    • With both Tableau Server visualizations and Tableau desktop visualizations, you can create URL actions, so that users can select data and then cause HTTP GET requests to URLS that are based on info in the selected data.

    • If you have a data source that Tableau doesn't yet provide a driver for (there are many including ODBC), then you can write a program using their data extract API to extract data from your custom source and make it available to Tableau. You can also publish that source to Tableau server as frequently as needed to keep your visualizations current.

    • If you have specialized functions on your database server, you can access them from Tableau calculations using their SQL pass through functions. You can also define a Tableau connection using arbitrary custom SQL which gives you another place to insert customizations.

    • Version 8.1 added integration with R so you can call R scripts from Tableau calculated fields.

    • Version 8.2 added a REST API to Tableau Server for administrative functions

    • Version 9.1 adds a Web Connector that is designed to let you provide custom code to connect to web accessible data sources

    • Version 10.1 Tableau added TabPy a local HTTP Python server that lets you execute Python functions from Tableau in the same way you can call R functions. The same hooks have now been extended to allow calls to Matlab functions.

    • There are also command line programs, tabcmd and tabadmin, that work with Tableau server that you can use to send commands to the server from your own scripts, but the REST API may be more convenient in many cases.

    • Tableau released several open source libraries, tools and examples at https://github.com/tableau One of these libraries, the document API, allows you to programmatically modify some attributes of Tableau workbook files.

    • Tableau released an extensions API in 2018 to allow developers to add custom functionality to Tableau dashboards.

    • Version 2019.3 adds a MetaData API using GraphQL to allow clients to query for information about the fields, types and attributes available in data sources published to Tableau Server's data catalog.

    Hopefully, they'll continue to add additional APIs and integration hooks, but those are most of the options available now.

      August 18, 2021 2:21 PM IST
    0
    1. Open the TSM command line/shell .
    2. Enter the following commands to set the host address, port values and connect timeout:

      tsm security maestro-tabpy-ssl enable --connection-type {maestro-tabpy-secure/maestro-tabpy} --tabpy-host <TabPy IP address or host name> --tabpy-port <TabPy port> --tabpy-username <TabPy username> --tabpy-password <TabPy password> --tabpy-connect-timeout-ms <TabPy connect timeout>

      • Select {maestro-tabpy-secure} to enable a secure connection or {maestro-tabpy} to enable an unsecured connection.
      • If you select {maestro-tabpy-secure}, specify the certificate file -cf<certificate file path> in the command line.
      • Specify the --tabpy-connect-timeout-ms <TabPy connect timeout> in milliseconds. For example --tabpy-connect-timeout-ms 900000.
    3. To disable the TabPy connection enter the following command

      tsm security maestro-tabpy-ssl disable

    Create your python script

    When you create your script, include a function that specifies a pandas (pd.DataFrame) as an argument of the function. This will call your data from Tableau Prep Builder. You will also need to return the results in a pandas (pd.DataFrame) using supported data types.

    For example to add encoding to a set of fields in a flow, you could write the following script:

    def encode(input):     
      le = preprocessing.LabelEncoder()
      Return pd.DataFrame({
        'Opportunity Number' : input['Opportunity Number'],
        'Supplies Subgroup Encoded' : le.fit_transform(input['Supplies Subgroup']),
        'Region Encoded' : le.fit_transform(input['Region']),
        'Route To Market Encoded' : le.fit_transform(input['Route To Market']),
        'Opportunity Result Encoded' : le.fit_transform(input['Opportunity Result']),
        'Competitor Type Encoded' : le.fit_transform(input['Competitor Type']),
        'Supplies Group Encoded' : le.fit_transform(input['Supplies Group']),
    })

    The following data types are supported:

    Data type in Tableau Prep Builder Data type in Python
    String Standard UTF-8 string
    Decimal Double
    Int Integer
    Bool Boolean
    Date String in ISO_DATE format “YYYY-MM-DD” with optional zone offset. For example, “2011-12-03” is a valid date.
    DateTime String in ISO_DATE_TIME format “YYYY-MM-DDT:HH:mm:ss” with optional zone offset. For example, “2011-12-03T10:15:30+01:00” is a vslid date.

    Note: Date and DateTime must always be returned as a valid string.

    If you want to return different fields than what you input, you'll need to include a get_output_schema function in your script that defines the output and data types. Otherwise, the output will use the fields from the input data, which are taken from the step that is prior to the script step in the flow.

    Use the following syntax when specifying the data types for your fields in the get_output_schema:

    Function in Python Resulting data type
    prep_string () String
    prep_decimal () Decimal
    prep_int () Integer
    prep_bool () Boolean
    prep_date () Date
    prep_datetime () DateTime
      November 18, 2021 12:01 PM IST
    0
  • At present, Tableau does not support plug-ins and does not provide a general-purpose scripting language.
    There is a currently an Idea on the Tableau website to add Ruby as a scripting language which may cover some of the functionality that is required. The Ideas section is regularly reviewed by Tableau's Product Management team and is the best way of suggesting new functionality for Tableau's products.
      December 30, 2020 10:16 AM IST
    0