superset icon indicating copy to clipboard operation
superset copied to clipboard

jinja templating in markdown element or in iframe URL

Open zufolo441 opened this issue 6 years ago • 8 comments

Hi, is there any plan to implement templating in markdown frames of dashboard v2 ? I'd need to capture url parameters for changing charts.

thanks!

zufolo441 avatar May 29 '20 11:05 zufolo441

Alternatively, it could be sufficient enable templating in iframe component, for changing values of json of the chart viewed inside iframe...

zufolo441 avatar May 30 '20 22:05 zufolo441

I think we have 2 ways to get markdown in a dashboard at this time, the native dashboard component, and the "Markup" visualization. I think it'd be possible to add that feature to the second one (as the markdown is process in the backend), but probably harder for the the dashboard-native component. I think the idea was to deprecate the Markup visualization though, but now that all visualizations are plugins, you can run always keep it around as a plugin.

mistercrunch avatar May 31 '20 05:05 mistercrunch

Thanks. I already edited MarkupViz in order to apply templates, and it works, but it isn't anymore possible add markup charts to dashboards because, I suppose, they are deprecated. Is it possible to re-enable this possibility? My idea is insert in markup visualization an with url of other charts with parameters. My main problem is that I have to draw country maps of every italian province and region, and I'd prefer to use only one chart instead of 130...

zufolo441 avatar May 31 '20 07:05 zufolo441

I tried to apply process_template() to iframe viz. I'm trying to call another chart with parameters in json data in url, for example %22select_country%22%3A%22{{url_param('cartina',default='Toscana_province_2020')}}%22 in place of original %22select_country%22%3A%22Toscana_province_2020%22

I tried to edit get_data() in this way: class IFrameViz(BaseViz):

"""You can squeeze just about anything in this iFrame component"""

viz_type = "iframe"
verbose_name = _("iFrame")
credits = 'a <a href="https://github.com/airbnb/superset">Superset</a> original'
is_timeseries = False
def query_obj(self):
    return None

def get_df(self, query_obj: Optional[Dict[str, Any]] = None) -> pd.DataFrame:
    return pd.DataFrame()

def get_data(self, df: pd.DataFrame) -> VizData:
    template_processor = get_template_processor(self.datasource.database)
    self.form_data['url']=template_processor.process_template(self.form_data['url'])
    return {"iframe": True }

If I look at json I see "url" field with parameters replaced by correct values, but url called by browser in order to fill page has parameters replaced by anything. example: in iframe URL I put ....&height={{url_param('altezza',default=300)}} in json of chart I see ...&height=300 but page has been called with ...&height=

Can anyone help me ?

zufolo441 avatar Jun 01 '20 09:06 zufolo441

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. For admin, please label this issue .pinned to prevent stale bot from closing the issue.

stale[bot] avatar Aug 01 '20 09:08 stale[bot]

Do you have any solution for this? @zufolo441

ranggarppb avatar Feb 24 '21 18:02 ranggarppb

no. I still search a solution to use variables outside SQL queries.....

zufolo441 avatar Jul 16 '22 21:07 zufolo441

Solution partially found, with handlebars. here I can insert an iframe with a query that returns json code for creating a slice.

zufolo441 avatar Jul 23 '22 09:07 zufolo441