|
| 1 | +.. _embedding-charts: |
| 2 | + |
| 3 | +======================================== |
| 4 | +Embedding Charts in Your Web Application |
| 5 | +======================================== |
| 6 | + |
| 7 | +.. default-domain:: mongodb |
| 8 | + |
| 9 | +.. contents:: On this page |
| 10 | + :local: |
| 11 | + :backlinks: none |
| 12 | + :depth: 1 |
| 13 | + :class: singlecol |
| 14 | + |
| 15 | +Overview |
| 16 | +-------- |
| 17 | + |
| 18 | +As a dashboard Author, you can embed charts into your own web sites, |
| 19 | +allowing people who are not Charts users to see your visualizations. |
| 20 | +You can either require a verified signature to accompany each data |
| 21 | +request, or allow anyone with the chart's identifying information to |
| 22 | +embed it in a web page. |
| 23 | + |
| 24 | +If you want strict control over who can embed your charts, use the |
| 25 | +:ref:`Verified Signature <require-authentication>` option. If your data |
| 26 | +is non-sensitive and you prefer a simpler embedding solution, use the |
| 27 | +:ref:`Unauthenticated Access <allow-unauthenticated>` option. |
| 28 | + |
| 29 | +.. _embedding-procedure: |
| 30 | + |
| 31 | +Procedure |
| 32 | +--------- |
| 33 | + |
| 34 | +From your dashboard tab, select the dashboard containing the chart you |
| 35 | +wish to make embeddable. From the dashboard, click the ellipsis |
| 36 | +(:guilabel:`...`) button at the top-right of the chart to access its |
| 37 | +embedding information. Select :guilabel:`Embed Chart` from the dropdown |
| 38 | +menu. |
| 39 | + |
| 40 | +If you have not already enabled embedding for the data source this |
| 41 | +uses, and if you are the data source owner, you have the opportunity to |
| 42 | +do so now. Click the :guilabel:`Enable embedding options` link. |
| 43 | + |
| 44 | +.. figure:: /images/charts/embed-chart-options.png |
| 45 | + :figwidth: 507px |
| 46 | + :alt: Embed a chart |
| 47 | + |
| 48 | +Once the data source has embedding enabled, you can choose to allow |
| 49 | +unauthenticated access or restrict access to those with a |
| 50 | +:ref:`verified signature <require-authentication>`. |
| 51 | + |
| 52 | +.. figure:: /images/charts/embed-chart.png |
| 53 | + :figwidth: 507px |
| 54 | + :alt: Embed a chart |
| 55 | + |
| 56 | +.. _allow-unauthenticated: |
| 57 | + |
| 58 | +Allow Unauthenticated Access |
| 59 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 60 | + |
| 61 | +To allow anyone with the chart link to embed the chart in a web page, |
| 62 | +select the :guilabel:`Unauthenticated` tab and toggle the switch marked |
| 63 | +:guilabel:`Enable unauthenticated access` to :guilabel:`On`. The HTML |
| 64 | +code necessary to embed the chart appears in the modal window. This |
| 65 | +HTML snippet is ready to copy and paste into an external web page. |
| 66 | + |
| 67 | +.. figure:: /images/charts/embed-chart2.png |
| 68 | + :figwidth: 508px |
| 69 | + :alt: Embed unauthenticated chart |
| 70 | + |
| 71 | +.. _require-authentication: |
| 72 | + |
| 73 | +Require Authentication for Access |
| 74 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 75 | + |
| 76 | +For increased security, you can require a verified signature to |
| 77 | +accompany each data request for an embedded chart. Select the |
| 78 | +:guilabel:`Verified Signature` tab and toggle the :guilabel:`Enable |
| 79 | +signed authentication acces` switch to :guilabel:`On`. |
| 80 | + |
| 81 | +.. figure:: /images/charts/embed-chart3.png |
| 82 | + :figwidth: 508px |
| 83 | + :alt: Embed authenticated chart |
| 84 | + |
| 85 | +In addition to the HTML iframe, the verified signature option requires |
| 86 | +some server-side code in order to work. The HTML snippet above shows |
| 87 | +what the iframe needs to look like, but it is not usable as-is. |
| 88 | +Your web application must use a secret embedding key to sign the URL |
| 89 | +and include a timestamp. |
| 90 | + |
| 91 | +.. _verified-signature: |
| 92 | + |
| 93 | +Verified Signature Generation |
| 94 | +----------------------------- |
| 95 | + |
| 96 | +To grant data access for embedded charts which require authentication, |
| 97 | +you must obtain an embedding key from the :guilabel:`Admin Settings` |
| 98 | +page. |
| 99 | + |
| 100 | +.. note:: |
| 101 | + |
| 102 | + You must be a :ref:`Project Owner <dashboard-permissions>` to access |
| 103 | + the :guilabel:`Admin Settings` page. For users with the |
| 104 | + :ref:`Project Owner <dashboard-permissions>` role, the |
| 105 | + :guilabel:`Admin Settings` link appears in the top right corner of |
| 106 | + the charts UI. As a non-admin user, you can still use embedded |
| 107 | + charts, but you will need to ask a Project Owner for a key. |
| 108 | + |
| 109 | +Once you have a key, you can create the server-side code required to |
| 110 | +generate the verified signature which must accompany a data request |
| 111 | +from an embedded chart. Code examples of how to generate a verified |
| 112 | +signature are available for the following languages and platforms: |
| 113 | + |
| 114 | +- `Node.js <https://github.com/mongodb/charts-embedding-examples/tree/master/node>`__ |
| 115 | +- `C# <https://github.com/mongodb/charts-embedding-examples/tree/master/c-sharp>`__ |
| 116 | +- `Java <https://github.com/mongodb/charts-embedding-examples/tree/master/java>`__ |
| 117 | +- `Python <https://github.com/mongodb/charts-embedding-examples/tree/master/python>`__ |
| 118 | +- `MongoDB Stitch <https://github.com/mongodb/charts-embedding-examples/tree/master/stitch>`__ |
| 119 | + |
| 120 | +Embedded Charts Error Codes |
| 121 | +--------------------------- |
| 122 | + |
| 123 | +If an embedded chart fails to render, an error code is displayed: |
| 124 | + |
| 125 | +.. list-table:: |
| 126 | + :header-rows: 1 |
| 127 | + :widths: 20 80 |
| 128 | + |
| 129 | + * - Error Code |
| 130 | + - Error Cause |
| 131 | + |
| 132 | + * - ``-1`` |
| 133 | + - Unknown error. |
| 134 | + |
| 135 | + * - ``1`` |
| 136 | + - Invalid tenant ID. Check the ``tenant`` field in the iframe |
| 137 | + HTML and make sure it matches what you see in the |
| 138 | + :ref:`Embed Chart <embedding-procedure>` modal window. |
| 139 | + |
| 140 | + * - ``2`` |
| 141 | + - Item not found. Check the ``id`` field in the iframe |
| 142 | + HTML and make sure it matches what you see in the |
| 143 | + :ref:`Embed Chart <embedding-procedure>` modal window. |
| 144 | + |
| 145 | + * - ``3`` |
| 146 | + - Embedding not enabled. Check the settings in your chart's |
| 147 | + :ref:`Embed Chart <embedding-procedure>` modal window. |
| 148 | + |
| 149 | + * - ``4`` |
| 150 | + - Embedding not allowed. Check the embedding settings in your |
| 151 | + chart's :ref:`data source <data-source-embedding>`. |
| 152 | + |
| 153 | + * - ``5`` |
| 154 | + - Invalid payload. Your application server is not creating a |
| 155 | + usable :ref:`signature <verified-signature>`. |
0 commit comments