stoddabr / react-tableau-embed-live

Wrapps Tableau Embedded API in a React Component
MIT License
22 stars 6 forks source link
tableau

Increment & Publish Deploy Example Site Test

React Tableau Embed Live

See the demo!

Embed your Tableau dashboards in React with confidence!

Other features:

Quickstart

Install via npm @stoddabr/react-tableau-embed-live:

npm install @stoddabr/react-tableau-embed-live

Then import, pass a source url and then badda-bing you're in bussiness.

Simple example using a public tableau embedding:

import * as React from "react";
import "./App.css";
import { TableauEmbed } from "@stoddabr/react-tableau-embed-live";

function App() {
  return (
    <div
      className="App"
      style={{
        alignItems: "center",
        display: "flex",
        justifyContent: "center",
        flexDirection: "column",
      }}
    >
      <h1>The Tableau Embedded API v3</h1>
      <h3>Now more lightweight, and backwards compatible!</h3>
      <TableauEmbed sourceUrl="https://public.tableau.com/views/WorldIndicators/GDPpercapita" />
    </div>
  );
}
export default App;

Demo

An example site lives in the folder example/react-tableau-embed-live-examples with useful wrapper components inside of example/react-tableau-embed-live-examples/src/tableau_examples.

To run demo on your machine:

# run once:
#   clone the repo
git clone https://github.com/stoddabr/react-tableau-embed-live.git
#   navigate to example folder
cd example/react-tableau-embed-live-examples
#   install example dependencies
npm i

# run every time:
#   run project in hot-reloading dev-mode
npm run dev

\ Props

Used internally by this library.

Prop Name Type What do Min. Library Version
sourceUrl string The URL of the Tableau dashboard. Can be a share or direct link. The host of this url will be used to fetch the Tableau API. 0.3.X
version string The version of the Tableau Embedding API to use. Defaults to "latest" which may change if you use Tableau Server or Cloud. Will always minify. If using a custom version, ensure the feature is available as per the changelog. Example: "3.1.0". 0.3.X
loadingSpinner React.ReactElement Custom loading spinner. By default this library uses a fork of lds-ripple 0.3.19
ref TableauVizRef (React.Ref) Forwarded reference to underlying <tableau-viz/> WebComponent used in the Tableau Embed API. To be used with a useRef hook. Useful for advanced callbacks. See the "Add/Remove Filter Buttons" example. 0.3.18

Props drilled directly into the Tableau Embed API's <tableau-viz> WebComponent. See documentation for full explination. This table simply explains how they are exposed. Because of Tableau Embed API idiosyncrasies, some of these may not work.

Prop Name Type What do Min. Library Version
height React.CSSProperties["height"] (number or string) Height of the Tableau Dashboard. Will default to the container (but may be glitchy). It's recommended to fix with same as authored Tableau dashboard. 0.3.X
width React.CSSProperties["width"] (number or string) Width of the Tableau Dashboard. Will default to the container (but may be glitchy). It's recommended to fix with same as authored Tableau dashboard. 0.3.X
["hide-tabs"] boolean Will hide toolbars on the Tableau Dashboard. Note: to set to false (and show tabs), pass undefined not false. Tableau's API appears to cast this prop to a string which makes false-> "false" -> which is truthy (i.e., boolean("false") === true is true). See example below. 0.3.X
toolbar "top" | "bottom" | "hidden" Location of the toolbars. 0.3.X
device "default" | "desktop" | "tablet" | "phone" Device layout to use. Defaults to "default" 0.3.X
token See Tableau docs See Tableau docs 0.3.22
["instance-id-to-clone"] See Tableau docs See Tableau docs 0.3.X
["disable-url-actions"] See Tableau docs See Tableau docs 0.3.X
SupportedEvent* (event: any) => void Callback function to be mounted directly on WebComponent. See list of supported events in the Tableau docs. For example onCustomViewLoaded={()=>console.log("hola world")} 0.3.X
onEventListener SupportedEvent* (event: any) => void Callback function to be mounted using an event listener. This may result in a different behavior. Similar name to props in row above only with "onEventListener" instead of "on" prefix. Callback function to be mounted directly on WebComponent. See list of supported events in the Tableau docs. For example OnEventListenerCustomViewLoaded={()=>console.log("hola world")} 0.3.X

Note: some props in require odd syntax to pass due to how tableau has hyphenated fields which JS is allergic to. To sidestep future compatibility issues, this library recommends using an odd syntax which involes spreading a temporary object. An example of this syntax can be seen in the simple example below with hide-tabs.

<TableauEmbed
  sourceUrl="https://public.tableau.com/views/WorldIndicators/GDPpercapita"
  {...{ "hide-tabs": showTab ? undefined : true }}
/>

Styling

The styles of the parent component of TableauEmbed is important and tricky to get correct. By default, without any height/width props passed, it will take up the height/width in the parent container. However, this will only happen if the tableau dashboard being embedded is NOT set to fixed mode or the size it's attempting is larger than it's range (tableau docs). Fixed dashboards should always be set to their exact dimensions and then scaled using JS/CSS transforms (for example, "the react way" in this article).

Prior updates of the Tableau Embedded API have broken this styling (specifically v3.2 -> v3.4). It's recommended for any project using this library to implement integration-level snapshot tests that check to ensure the TableauEmbed component is styled correctly.

Licences

When using this library ensure you are following Tableau's licensing agreement.

Limitations

If you discover anything other limitations please create an issue, and/or ping me on Twitter: @sliceofbrett

Contributions

Contributions welcome!!

To contribute, please fork, then create an atomic PR that describes the fix or feature. If you're not sure what to contribute, see the above list of limitations, or any open issues without an active dev branch.

This project is setup with some CICD github actions to make this process easier. Every push request will trigger actions to increment the npm patch version, build the project, publish the project to npm, build the examples site, and then publishes the example site to a dedicated branch.