|
| 1 | +--- |
| 2 | +id: add-support-for-externally-shared-dashboards |
| 3 | +title: Add support for externally shared dashboards |
| 4 | +description: How to add support for externally share dashboards (previously called Public dashboards). |
| 5 | +keywords: |
| 6 | + - grafana |
| 7 | + - plugins |
| 8 | + - plugin |
| 9 | + - externally shared dashboards |
| 10 | + - public dashboards |
| 11 | + - data source |
| 12 | + - datasource |
| 13 | +--- |
| 14 | + |
| 15 | +[Externally shared dashboards](https://grafana.com/docs/grafana/latest/dashboards/share-dashboards-panels/shared-dashboards/#externally-shared-dashboards) (previously called Public dashboards) allow Grafana users to share access to their dashboards with anyone, without needing to add them to their Grafana organization as a user. When a dashboard is accessed in this way, it retrieves the query from the backend, instead of receiving it from the frontend. This is to avoid exposing sensitive data and performing unauthorized queries. |
| 16 | + |
| 17 | +Because of this, it's necessary to not pass any frontend-transformed body to the request, as it won't be used in the externally shared dashboard panel request. |
| 18 | + |
| 19 | +:::note |
| 20 | + |
| 21 | +Frontend data sources are not compatible with externally shared dashboards. |
| 22 | +To convert a frontend data source plugin into a backend plugin, refer to |
| 23 | +[convert a frontend data source to backend](./convert-a-frontend-datasource-to-backend). |
| 24 | + |
| 25 | +::: |
| 26 | + |
| 27 | +## Support externally shared dashboards in your data source plugin |
| 28 | + |
| 29 | +To make your data source plugin work in an externally shared dashboard scope, follow these steps: |
| 30 | + |
| 31 | +1. Extend your DataSource class from `DataSourceWithBackend` |
| 32 | + |
| 33 | + ```ts |
| 34 | + export class MyDataSourceClass extends DataSourceWithBackend<TQuery, TOptions> { |
| 35 | + // your logic |
| 36 | + } |
| 37 | + ``` |
| 38 | + |
| 39 | +2. Implement the `query` method with your customized code, if necessary. Don't transform the request body if this will change the backend query response (targets property). This body won't be passed as argument when calling the shared externally dashboard endpoint. |
| 40 | + |
| 41 | + Then, call `super.query(request)`. |
| 42 | + This is where the externally shared dashboard endpoint is called. |
| 43 | + |
| 44 | + ```ts |
| 45 | + export class MyDataSourceClass extends DataSourceWithBackend<TQuery, TOptions> { |
| 46 | +
|
| 47 | + query(request: DataQueryRequest<TQuery>): Observable<DataQueryResponse> { |
| 48 | + // your logic |
| 49 | + return super.query(request).pipe( |
| 50 | + map((response) => { |
| 51 | + // your logic |
| 52 | + }) |
| 53 | + ); |
| 54 | + } |
| 55 | + } |
| 56 | +
|
| 57 | +3. Add `"backend": true` to your `plugin.json` |
| 58 | +
|
| 59 | + ```json title="src/plugin.json" |
| 60 | + "backend": true |
| 61 | + ``` |
0 commit comments