Add extra Superset assets#
Developers can use the superset-extra-assets patch to add extra assets (charts, datasets, dashboards, databases) to Superset that will be imported at initialization.
The patch is expected to be a list of assets (with an extra attribute called _file_name to uniquely identify each asset). Each asset should be a valid yaml object with the attributes that Superset expects for each asset type. See
aspects assets for examples of asset yaml declarations.
Assets in a tutor inline plugin using the patch would look like:
name: custom-inline-plugin
version: 0.1.0
patches:
superset-extra-assets: |
- _file_name: my-dashboard.yaml
dashboard_title: "..."
...
- _file_name: my-chart.yaml
slice_name: "..."
...
- _file_name: my-database.yaml
database_name: "..."
...
- _file_name: my-dataset.yaml
table_name: "..."
...
Creating a Tutor plugin#
Use the Tutor Plugin Cookiecutter to create a skeleton plugin. We have created tutor-contrib-aspects-sample as an example.
Create a patch file that will recursively include all of your Superset assets from
templates/build/assetsinto Aspects when the plugin is enabled andtutor config saveis run.{% for file in "aspects-sample/build/assets"|walk_templates %} --- _file_name: {{ file.split('/')[-1] }} {% include file %} {% endfor %}
Attention
The directory containing
assetsmust be included in ENV_TEMPLATE_TARGETS. Since this defaults tobuildandapps, you can either add your asset files to one of these directories, or add an additional target to the plugin file.Create a requirements.txt with
rufffor formatting.
Import assets into plugin#
From the Superset UI, you can export your dashboard, which will download to your local computer as a
.zipfile.As long as you are running Aspects 1.0.3 or newer, you can use this command to unzip the file to your plugin directory.
tutor aspects import_superset_zip <path to your dashboard>.zip --base_assets_path <path to your extension>/templates/build/assets/
This command does several things to make import safer and easier including:
Check for some required security fields
Safely name files so that charts with duplicate names don’t overwrite each other
Check that certain fields use Tutor settings instead of hard coded values
Add a special
_file_namekey that tells Aspects what name to use for the file when importing back to Superset
Before importing a dashboard back into Superset, you will need to manually add a _roles key, which sets the permissions for who can view the dashboard.
_roles: - '{{ SUPERSET_ROLES_MAPPING.instructor }}'
In addition to the default roles (student, instructor, operator, admin) you can also add custom roles in a
superset_rolespatch.
Warning
When a Superset zip is exported it will contain any datasets and databases needed for all of the charts in that dashboard. This may include the default xapi and MySQL databases or Aspects datasets that you probably do not want to overwrite, and can include their passwords!
Use caution when importing datasets or databases into your plugin - only ones you have created yourself should exist in your plugin.
If you truly mean to overwrite the default databases or datasets, make sure to remove any sensitive information such as passwords from the yaml files before importing.
If you accidentally overwrite a default database, you can reset it by:
Disabling your plugin (
tutor plugins disable <your plugin>)Running
tutor config saveandtutor <local|dev|k8s> do import-assetsto reset the assetsRe-enabling your plugin
Update Superset assets#
Once you have your files imported to the plugin, make sure it is installed and enabled in your Tutor environment, then use import-assets to update your Superset assets.
pip install <your package>
tutor plugins enable <your plugin>
tutor config save
tutor <local|dev|k8s> import-assets