Forking a dashboard

This would help very much and save hours for us. The current situation is that if we want to have two similar dashboard, that differ only in their parameters, we need to add widget by widget to each dashboard. We want to prevent this repetition and time-cost for these cases where dashboard are so similar. It would be of great value to us.

Optimally, we would want to have the option to copy a dashboard. This way, we can have two (or more) similar dashboards, which will differ in the parameters we pass in to them.
Thanks!

The problem I’ve noticed with this is that each query can only cache one result at a time. If you change the params, the previous cached results are lost, and your other dashboards all return errors.

I’m trying to figure out a way around this too, so I can have 1 query, pass different params on each dashboard, and cache results for each. But right now it doesn’t seem possible?

This is correct.

The accepted way to fork a dashboard is using the API to rebuild it from scratch. If you need the results to cache then you would also fork the queries.

Is there any plans to add this functionality in the near future?

2 Likes

It’s not part of the product, but we’re preparing an API script that can do this automatically. You can follow development here:

1 Like

@jesse this sounds great, but any chance for an a short walkthrough on how to use it?

Here is my attempt

  1. pip3 install redash_toolbelt (not sure if this is needed but it did quell some loud noises)
  2. git clone git@github.com:getredash/redash-toolbelt.git
  3. cd redash-toolbelt
  4. git checkout issue-14
  5. pip3 install click
  6. python3 -m redash_toolbelt.examples.clone_dashboard_and_queries https://bla.bla.com/ blop-dash pref-blip

OK, this worked.
I followed this up with some scripts to update the queries in a dashboard to a new data source.

for reference this returns the dashboard id, slug, and query ids, for further editing.

dashj = requests.get(url=f'{base}/api/dashboards/{dash["slug"]}', headers=headers).json()
ans = {s:dashj[s] for s in 'slug name id'.split()}
ans['queries'] = [dd['visualization']['query']['id'] for dd in dashj['widgets'] if 'visualization' in dd]

and this is enough to edit the query

json = {'query': query,
            'name': qname, 
            'data_source_id': client_data_source_id,
            'is_draft': False
            }
        
        # update
    res_post= requests.post(url=f'{base}/api/queries/{id}', headers=headers, json = json)

note: after changing the data source for a query you probably want to refresh the results by posting to f'{base}/api/queries/{id}/results'

1 Like

I did this feature, if you also need, contact me.

do you have it in a branch?

I am a fresh man, I am learning how to pull request.

I post my python code on this branch, if you also need js code, i can post it too.

You can contact me, This is my github link

I’m getting what looks like a JSON parsing error when trying to run the redash-toolkit cloning script. Any ideas what’s going on here and/or how to fix it?

% python3 -m redash_toolbelt.examples.clone_dashboard_and_queries http://redash.blahblah.com campaign-insights clone
API Key: XXXXXXXXXXXX
Traceback (most recent call last):
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/sam/redash-toolbelt/redash_toolbelt/examples/clone_dashboard_and_queries.py", line 84, in <module>
    main()
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/Users/sam/redash-toolbelt/redash_toolbelt/examples/clone_dashboard_and_queries.py", line 80, in main
    duplicate(client, slug, prefix)
  File "/Users/sam/redash-toolbelt/redash_toolbelt/examples/clone_dashboard_and_queries.py", line 31, in duplicate
    old_vs_new_query_pairs = [
  File "/Users/sam/redash-toolbelt/redash_toolbelt/examples/clone_dashboard_and_queries.py", line 34, in <listcomp>
    "new_query": client.duplicate_query(
  File "/Users/sam/redash-toolbelt/redash_toolbelt/client.py", line 76, in duplicate_query
    new_query = response.json()
  File "/usr/local/lib/python3.9/site-packages/requests/models.py", line 910, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

hmmm that’s unusual. Can you open an issue against redash-toolbelt with steps to reproduce? I use this script a lot and haven’t seen this bug.

I’m not a developer/engineer and opening a GitHub issue with steps to reproduce is a little out of my wheelhouse. For what it’s worth, I did just create a virtual environment on my local machine to run the script in just to make sure it wasn’t a strange environment conflict. I got the same error.

Python 3.9.6
Redash v8

No worries! I’ll add this to my list to investigate when I have a moment. I wonder if V8 is the issue? The script was written and tested on V9 and V10.

Hi bro i need help in this script. (forking a dashboard). how can i contact you, your github is not reachable

jesse can you tell me please where i can get parameters?
like slug,api key to use this api.
if its possible can we also have tutorial to implement this script?
Thanks in advance!!

you can contact me yankeeguyu@gmail.com

Thanks a lot. i have sent u mail

My new github link