Skip to main content

Build Reusable Dashboards for Multiple Clients

Introduction

Let's say that you're creating reports for multiple clients with the following requirements:

  • Reusability. Reuse a standard dashboard template for all clients. Updating the template and all client dashboards should be updated at once.
  • Client-specific customizations. Customize charts in a specific client dashboard without affecting other clients.
  • Dynamic datasource. Each client has a separate datasource that is used in their respective dashboards.

This docs shows you how to build a resuable dashboard for all clients but can be customized for specific purposes.

Overview

Step-by-step solution

  1. Define a master dashboard template with reusable chart components.
  2. Build client dashboards from master dashboard template. Updating the template should propagate changes to all client dashboards.
  3. Customize specific client dashboards. Point each client dashboard to respective client's datasource and add new charts into client dashboard.

Define a master dashboard template

Create a master dashboard template as followed:

// In master_template.page.aml

// Define master dashboard template
Dashboard master_dashboard_template {
title: 'eCommerce Business Metrics'
block v1: VizBlock {
viz: PieChart {
// A default dataset. Can refer to client's dataset later
dataset: default_dataset
//...
settings {
// This draws the chart as a donut
display_as_donut: false
// ...
}
}
}
// ...
}

Define master dashboard template

Build client dashboards from the master dashboard template

Once you define a dashboard template, use AML Extend to build client dashboards. Extending a dashboard lets you inherit all of its properties, including title, charts, filters and settings.

// In client_dashboard.page.aml
// Extend the master dashboard template into a client dashboard
Dashboard client_dashboard = master_dashboard_template.extend({})

The client dashboard will look the same as the master dashboard template.

Let's edit the pie chart in the master dashboard template so that it shows a donut instead of a pie.

// In master_template.page.aml
Dashboard master_dashboard_template {
title: 'eCommerce Business Metrics'
block v1: VizBlock {
viz: PieChart {
// A default dataset. Can refer to client's dataset later
dataset: default_dataset
//...
settings {
// Changed this to `true` to display a donut pie
display_as_donut: true
// ...
}
}
}
// ...
}

You should see changes being reflected in the client dashboard.

Edit and propagate

Important Note

Please note that, once you use Extend, Const or Function, you need to define charts, layouts and positions as code instead of UI. Editing in UI mode will not work if your code contains AML Extend. This is a known limitation that we're working on removing in the near future.

By extending the master dashboard template, you can add/edit the template and have changes propagated to all client dashboards automatically.

Customize specific client dashboards

You can also use AML Extend to override a chart in the dashboard template. Define a new bar chart and use this instead and of the pie chart.

// In client_dashboard.page.aml
Dashboard client_dashboard = master_dashboard_template.extend({
// Define a bar chart for revenue share instead of a pie chart
block v1: BarChart {
dataset: default_dataset
// ...
}
}
})

Now the client dashboard will use the bar chart instead of the pie chart. This doesn't affect the dashboard template any other client dashboards you may have.

Replace pie chart with bar chart

Finally, you can use AML Function that accepts a dataset parameter and returns a pie chart. This will allow you to dynamically point any chart to a specific client's datasource.

// In client_dashboard.page.aml
// Refactor this function to accept a dataset param
Func getRevenueShareBarChart(dataset_param) {
VizBlock {
viz: BarChart {
// Use the dataset param instead of hard-coded value
dataset: dataset_param
// ...
}
}
}

Dashboard client_dashboard = master_dashboard_template.extend({
// Call the function with client's actual datasource
block v1: getRevenueShareBarChart(client_dataset);
})


Let us know what you think about this document :)