redash icon indicating copy to clipboard operation
redash copied to clipboard

Choropleth: allow to use custom maps

Open kravets-levko opened this issue 5 years ago • 24 comments

What type of PR is this? (check all applicable)

  • [x] Feature

Description

Allow user to type arbitrary GeoJSON URL; existing build-it maps are available as dropdown options. Also, now instead of setting "Key Type" (type of key field from query result) user should map query result field to one of GeoJSON field.

Also fixed few small bugs in visualization.

Related Tickets & Documents

https://discuss.redash.io/t/choropleth-map-per-regions/4437

Mobile & Desktop Screenshots/Recordings (if there are UI changes)

image image

kravets-levko avatar Jan 29 '20 09:01 kravets-levko

The only thing that really makes this feature completely useless is this:

image

@arikfr Do you have any ideas what we can do with it?

kravets-levko avatar Jan 29 '20 09:01 kravets-levko

@kravets-levko not sure 🤔 The simplest solution? Give up on dynamic values there and keep adding different maps to our build. We should just make it very simple and documented process, so anyone can make a PR for this.

arikfr avatar Jan 29 '20 09:01 arikfr

@arikfr How about adding connect-src *; to default CSP rules? According to docs, it will allow only requests triggered by JS code (and it fixes the issue mentioned in my first comment - I already tried it on my dev instance).

kravets-levko avatar Jan 29 '20 10:01 kravets-levko

Everything works fine, except of that CSP issue :point_up:

kravets-levko avatar Jan 29 '20 22:01 kravets-levko

@arikfr How about adding connect-src *; to default CSP rules? According to docs, it will allow only requests triggered by JS code (and it fixes the issue mentioned in my first comment - I already tried it on my dev instance).

Allowing requests to be triggered by JS code sounds like a potential risk, and the kind of risk CSP supposed to prevent.

I thought of a different solution: have a Proxy endpoint in Redash that loads this JSON endpoint and returns it. The complex part is to make this endpoint secure by checking that this URL is indeed in the visualization definition.

arikfr avatar Jan 30 '20 09:01 arikfr

The complex part is to make this endpoint secure by checking that this URL is indeed in the visualization definition.

But this actually doesn't have to be that hard:

  1. Make a call to /api/resource-proxy with params: URL to load & visualization id.
  2. In the handler, load the visualization, check that it actually defines the URL.

Only issue: what to do before saving? :|

arikfr avatar Jan 30 '20 09:01 arikfr

Proxy is an option of course.

Only issue: what to do before saving? :|

What if proxy instead of checking visualization object will just allow to load any JSON files? Even if we'll need such a feature in other visualization (maybe one day?) - most likely we'll not need anything except of JSON. So proxy may load URL, check if it returned JSON and then pass that JSON to frontend. And of course allow only GET methods. Does it sound safe?

kravets-levko avatar Jan 30 '20 09:01 kravets-levko

Thinking of it; making only GET requests should be fine.

arikfr avatar Jan 30 '20 09:01 arikfr

@arikfr I added a basic implementation of proxy to load custom maps in https://github.com/getredash/redash/pull/4599/commits/813d97a62ca256327f3dd317d54b5f91a9b41f7e Most likely it has to be improved, so please review it - I'll appreciate any suggestions about it :bowing_man:

kravets-levko avatar Feb 11 '20 10:02 kravets-levko

Another relevant idea to discuss (and possibly implement): here I added some more metadata to Choropleth maps, but having it in our codebase will make it harder to add custom maps. The idea is to embed those metadata into GeoJSON files (it's allowed by GeoJSON specs). It will solve problem with custom maps, but also there are few cons: 1) map name couldn't be embedded because it's needed before the file is loaded, and 2) it will be a bit harder to find those mappings (e.g. to fix them).

kravets-levko avatar Sep 24 '20 11:09 kravets-levko

Is this still being considered? Would love to see this feature added.

jimsparkman avatar Oct 07 '20 20:10 jimsparkman

Hi @jimsparkman! Yes, I'll resume my work on it soon. I have to re-think some details first

kravets-levko avatar Oct 07 '20 20:10 kravets-levko

@kravets-levko are u able to estimate any deadline? We use redash for our clients (big hospitals in PL) and we need to analyze the patients diagnosis' distribution. This would be a great feature for us to have it in redash. Currently the client has to speak with ESRI which of course cost a lot of money.

opioom avatar Nov 27 '20 10:11 opioom

Hi @opioom! Sorry, no any estimates for now. I totally understand how useful this feature is, but ATM I'm loaded with other stuff.

kravets-levko avatar Nov 27 '20 11:11 kravets-levko

great job. when to merge to the master branch?

dengc367 avatar Dec 18 '20 11:12 dengc367

Nice work on this! Any update yet on when this will be merged?

chrispruitt avatar Dec 28 '20 21:12 chrispruitt

it's been 6 months since my last post so....do we have any progress? Any other options like workaround that could help to me visualize the PL regions with any data?

opioom avatar Feb 26 '21 11:02 opioom

it's been 6 months since my last post so....do we have any progress? Any other options like workaround that could help to me visualize the PL regions with any data?

Waiting for this great feature too, for the moment I "dirty" replaced map files (countries.geo.json and japan.prefecture.geo.json) by files with same structure and names but with my own data (square grid and municipalities).

I created specific volumes for it.

    volumes:
      - /opt/redash/maps/countries.geo.json:/app/client/dist/data/0962607.countries.geo.json
      - /opt/redash/maps/japan.prefectures.geo.json:/app/client/dist/data/650f3ee.japan.prefectures.geo.json

Capture d’écran du 2021-02-27 18-42-29

mathieubossaert avatar Feb 27 '21 17:02 mathieubossaert

@mathieubossaert Thank you so much! Works well 🙌🏻

edouardjmn avatar Mar 31 '21 10:03 edouardjmn

@mathieubossaert that's sounds like a solution! Do you have any detailed guide how to do that? I desperate need that function for healthcare analysis.

opioom avatar Aug 30 '21 19:08 opioom

Hi @opioom , I will document this trick / workaround after the release of v10.

mathieubossaert avatar Sep 21 '21 13:09 mathieubossaert

@opioom As promised on september. We "simply" need to change the content of the 3 geo.json files (keeping same names) used by redash, with your own content. In my case I needed to show 3 kind of maps :

  • cities and villages from Occitanie
  • 10km square mesh.
  • french "Departements"

So I replace Japan prefectures, counties and USA geojson files with mine.. Let's say my geo.json files are located on the host into /opt/redash/maps/ directory. Their names are

  • communes_occitanie.geo.json
  • mailles_10km.geo.json
  • departements.geo.json

We "simply" need to mount server container geojson files to the hosted mines. In the end of the server section of the docker-compose file, add

    volumes:
      - /opt/redash/maps/communes_occitanie.geo.json:/app/client/dist/data/0962607.countries.geo.json
      - /opt/redash/maps/mailles_10km.geo.json:/app/client/dist/data/dac34f3.japan.prefectures.geo.json
      - /opt/redash/maps/departements.geo.json:/app/client/dist/data/eed73d1.usa-albers.geo.json

Before that, you can check the name of the files used by redash container (name changes for a file on V10 upgrade on my instance)

docker exec -t -i redash_server_1 ls /app/client/dist/data/ 

0962607.countries.geo.json
eed73d1.usa-albers.geo.json dac34f3.japan.prefectures.geo.json

mathieubossaert avatar Dec 07 '21 12:12 mathieubossaert

Thanks a lot @mathieubossaert!! Will try to follow your guide on my test env. Edit: I've made a small modification because it didn't work via docker compose. I simply replaced json files inside redash_server (docker cp) with my own json files. The only fix I have to make are missing labels on a map, but it's probably related to the json file structure.

opioom avatar Dec 10 '21 21:12 opioom

Realise this is an old PR. I was wondering whether it is possible to customise the polygons / geojson used by the choropleth visualisation? Would be happy to contribute to get this integrated.

mathewtrivett avatar Jun 05 '22 12:06 mathewtrivett

@kravets-levko , thanks for the PR! We've updated a lot of things now that we're Community-driven so - if you're still interested (or @mathewtrivett ) in getting this merged - would you mind rebasing off master to re-run the CI, as well as updating merge conflicts?

We're trying to clean up our PR todo list, so if you're not interested, that's fine - we'll close the PR in about a week if we don't hear back. If you're interested in reopening the PR afterwards, we would also very much welcome that.

guidopetri avatar Jul 21 '23 19:07 guidopetri

Lets keep this one around for a while longer. It'll probably need to be reworked, but it's too important to just lose to history in the short term. :smile:

justinclift avatar Jul 22 '23 08:07 justinclift