0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Tableau(タブロー)】1つの画面に複数のTableauを表示する方法

0
Last updated at Posted at 2026-11-20

目次

はじめに

  • ユーザー画面:Tableauのダッシュボードを2つ表示
  • それ以外の画面:1つずつ

という指示があり、今回はフロントエンドを担当しました。

複数表示する場合の実装方法についての記事があまりなかったので、参考になればと思います。

前提

  • Tableau埋め込み用のAPIを呼び出す
  • バックエンド側からsrc_urlとtokenが返却される
  • tableau-vizタグにURLとtokenを設定する

今回のポイント

  • Tableauのビュー1つにつき、1回APIが呼び出される
  • しかし画面Aに関しては同じtokenを用いる
  • バックエンド側では上記の対応を行わないのでフロント側で対応する

方法

マニュアルの確認

公式マニュアルの複数のビューまたはAsk Dataレンズを埋め込む | Tableau埋め込みAPI より、

複数のビューを埋め込む場合は、すべての埋め込みコンポーネントに同じJWTを使用するようにしてください。
埋め込みコンポーネントごとに異なるトークンを使用すると、予期しない動作が発生し、正しく読み込まれる場合もあれば、ユーザーにサインインを求められる場合もあります。

属性を追加

今回は複数表示したいTableauのタグにforce-token-sync属性を付ける方法で進める。

これにより、1つ目のTableauダッシュボードにサインインし、2つ目のダッシュボードはそのセッションを共有して使用するようになる。

※注意点:force-token-sync属性はTableau Embedding APIのスクリプトの中にある属性だがマニュアルには記載がない。Tableau がスクリプト(latest)を更新したときに、動きが変わる可能性がある。

コード

/src/global.d.ts

import type { DetailedHTMLProps, HTMLAttributes } from 'react';

interface Window {
  someFunction: () => void;
}

declare module 'react' {
  namespace JSX {
    interface IntrinsicElements {
      'tableau-viz': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement> & {
        src?: string;
        token?: string;
        width?: string | number;
        height?: string | number;
        toolbar?: string;
        hideTabs?: boolean;
        forceTokenSync?: boolean;
      };
    }
  }
}

/src/components/Elements/TableauViz.tsx

import React from 'react';
import { useEffect, useRef, useState } from 'react';

import { logger } from '@/core/config/logger';
import { 省略 } from '@/core/config/tableau';
import { TableauEmbedLoaderResult } from '@/core/loaders/tableau-embed-loader';

type Props = {
  tableauViewKey: TableauViewKey;
  tableauEmbedResult: TableauEmbedLoaderResult;
  id?: string;
  forceTokenSync?: boolean; // これがポイント
};

type VizLoadErrorDetail = {
  errorCode: string;
  message: string;
};

export const TableauViz = (props: Props) => {
  const { 
      tableauViewKey, 
      tableauEmbedResult, 
      id = 'tableau-viz', 
      forceTokenSync = false // デフォルトはfalse
  } = props;

// 途中のコード省略

  return (
    <tableau-viz
      key={tableauEmbedResult.data.token}
      ref={vizRef}
      id={id}
      src={tableauEmbedResult.data.srcUrl}
      token={tableauEmbedResult.data.token}
      width={TABLEAU_VIZ_DEFAULT_OPTIONS.width}
      height={TABLEAU_VIEWS[tableauViewKey].height}
      hideTabs={TABLEAU_VIZ_DEFAULT_OPTIONS.hideTabs}
      toolbar={TABLEAU_VIZ_DEFAULT_OPTIONS.toolbar}
      forceTokenSync={forceTokenSync}
    />
  );
};

/src/features/summary/index/UserPage.tsx

import { logger } from '@/core/config/logger';

import { useTableauEmbedData } from '@/features/summary/index/hooks';
import { DefaultLayout } from '@/components/Layouts';
import { TableauViz } from '@/components/Elements';

export const UserPage = () => {
  logger.info('<-- UserPage -->');

  const { user, setting } = useTableauEmbedData();

  // 2つのビューで同じサインイン(セッション)を使うため、forceTokenSyncを指定
  return (
    <DefaultLayout>
      <TableauViz
       tableauViewKey="USER"
       tableauEmbedResult={userData}
       forceTokenSync
      />
          
      <TableauViz
       tableauViewKey="SETTING"
       tableauEmbedResult={settingData}
       forceTokenSync
      />
    </DefaultLayout>
  );
};

参考サイト

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?