URL filter parameters in Apache Superset dashboards
Asked Answered
S

4

5

I'm trying to create simple superset dashboard with a single chart (Big Number) that will filter data based on URL parameter passed to the dashboard. I've tried to fallow this Apache Superset Dashboard Filter with URL parameter ). I've used pattern &preselect_filters={"CHART-ID":{"tableColumnName1":["value1"]}} and then tried to define new filter in a chart like tableColumn = {{ filter_values('tableColumnName1')[0] }}, but this generates error. From my observation it resolves this expression without looking for query param.

How should I use it? Is there a documentation somewhere?

My superset version is 0.37.0

Stound answered 18/9, 2020 at 6:50 Comment(0)
M
6

You can achieve this on Superset with the following syntax:

http://{url}:8088/superset/dashboard/{dashboard_id}/?preselect_filters={{"chart_id"}:{{"column_to_be_filtered"}: {"value_to_be_filtered"}}}

Example

http://0.0.0.0:8088/superset/dashboard/1/?preselect_filters={"10": {"country": "France"}}

For the ID's

  • Chart/Slice: Click on Edit chart then under parameters look for slice_id

  • Dashboard: Click on Edit record and notice the last number on the URL: http://0.0.0.0/dashboard/edit/9

Marella answered 23/9, 2020 at 2:49 Comment(2)
Thanks @Marella for the reply! Unfortunately I'm missing sth because this doesn't work for me. I've used link: xxx:8080/superset/dashboard/test2/?preselect_filters={"26":{"marker":"KR21"}} Where my dashboard name is test2 and the only chart has id = 26. In this chart I've tried to add filter marker = 'KR2' and later alter it with query param I've mentioned and nothing happened. I've also removed this filter form chart and tried again - nothing :(Stound
The URL uses the dashboard ID and not the name, unless you have enabled a slug. But I suggest you select the filters on the dashboard and then save the dashboard using the "Save as" option under EDIT DASHBOARD menu. When you reopen it the URL will have the preselect filters.Marella
A
6

This is different now that the filter box is deprecated and all dashboards use native filters. You need to extend the dashboard URL with the "?native_filters=" RISON syntax, which looks like this:

?native_filters=(NATIVE_FILTER_ID:(__cache:(label:'FILTER_VALUE',validateStatus:!f,value:!('FILTER_VALUE')),extraFormData:(filters:!((col:COLUMN_NAME,op:IN,val:!('FILTER_VALUE')))),filterState:(label:'FILTER_VALUE',validateStatus:!f,value:!('FILTER_VALUE')),id:NATIVE_FILTER_ID,ownState:()))

  • NATIVE_FILTER_ID you can find in the "Edit dashboard properties" > "Advanced"
  • FILTER_VALUE is the thing you want entered into the filter
  • COLUMN_NAME is the name of the column you are filtering on

Here are some links with relevant information:

Amador answered 7/6, 2022 at 5:41 Comment(4)
This worked for me, can i ask you where is this documented? I ve been looking around, where to learn more about this nartive filters but cant find much informaiton in the docsHyperactive
@Hyperactive I haven't found any docs for this, only the links I provided.Amador
Additionally, if you would like to use jinja filters instead of native filters, you could probably use the url_param jinja macro. superset.apache.org/docs/installation/sql-templating/…Amador
Thanks, I managed to get it work for a String filter but I can't make it work for a time range filter. Has someone managed to set a "filterType": "filter_time" ?Faxen
O
1

You can open your dashboard, filter like you want to see and, in bullet menu (top right), click in "Copy chart URL". The URL is a shortened URL that redirects to a pre-filtered version of your dashboard.

Because the name of menu option, I don't know if this is a feature or a useful bug.

Ortrude answered 8/2, 2022 at 21:48 Comment(0)
T
0

First you have to enable the flags in the superset_config.py file

FEATURE_FLAGS = {"DASHBOARD_FILTERS_EXPERIMENTAL": True, "DASHBOARD_NATIVE_FILTERS_SET": True, "DASHBOARD_NATIVE_FILTERS": True, "DASHBOARD_CROSS_FILTERS": True, "ENABLE_TEMPLATE_PROCESSING": True}

And then follow the below process

?native_filters=(NATIVE_FILTER_ID:(__cache:(label:'FILTER_VALUE',validateStatus:!f,value:!('FILTER_VALUE')),extraFormData:(filters:!((col:COLUMN_NAME,op:IN,val:!('FILTER_VALUE')))),filterState:(label:'FILTER_VALUE',validateStatus:!f,value:!('FILTER_VALUE')),id:NATIVE_FILTER_ID,ownState:()))

  1. NATIVE_FILTER_ID you can find in the "Edit dashboard properties" > "Advanced"
  2. FILTER_VALUE is the thing you want entered into the filter
  3. COLUMN_NAME is the name of the column you are filtering on

And next in your superset URL include this as query parameters.

Thaddeusthaddus answered 17/10, 2022 at 6:56 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Sniggle

© 2022 - 2024 — McMap. All rights reserved.