-
-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added the slider and the callback for interactivity #8
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for this nice PR @pechouc !
This slider seems to perfectly match the opacity filtering onto the map risk layer.
I'll review in depth soon 👍
Just checked locally from your branch everything's fine and smooth.
I think that we can keep on adding changes on splitted on both
I agree it seems a bit straight forward but if no other option then we'll stick to it. Not possible to force style param |
Very much agreed!
At first, I tried to only change the Then, I tried to only modify the And finally, going one step above to the map object seemed to work. But let me know if you have any other idea! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Akilditu, do you prefer that I close this PR and merge the branch into master (possibly as a first version) or that I leave it open for you to have time to dig deeper? |
Did not find anything better, ok to close & merge ! |
Added the slider and the callback for interactivity (#8)
Aim of the Pull Request
The goal of this PR is to add the slider that enables users to modify the opacity of department colours in the "Niveaux de Risque" dashboard. Since it is a relatively small feature, I thought that we could directly hold the conversation about how to improve it directly in this pull request.
Questions
The slider currently looks like:
What do you think of the format of the slider? NB - as it might not be clear on the picture: marks are just indicative and can be clicked directly by the user, but any value between 0 and 1 can be chosen with a step of 0.01.
Would you like me to add it to the homepage or should we keep it only in the "Niveaux de Risque" dashboard for now?
As you will see, for the callback, I could not find a "lighter" solution than re-instantiating the
colorbar
and thegeojson
object. I have tried to find another way as I suspect this is a disproportionately heavy operation regarding the importance of the feature itself but nothing else worked. At least, it seems to work fine locally and doesn't break other callbacks but if you have any other idea, I would be glad to try them out!Would you want some context about the Dash component used to create the slider, this page is very detailed about it.
Details of changes in the files
main.py
Added a
dash_leaflet
import, used when changing thechildren
of the map object in the new callback. Same goes for the import ofbuild_risks_geojson_and_colorbar
- used to re-instantiate the colorbar and the GeoJSON as evoked previously - andbuild_info_object
from other Python files.Added the callback related to the slider, allowing users to choose the level of colour opacity they want to apply to the map. The way it works is not really satisfactory as the change it implies seems slightly disproportionate to me but I could not find any other solution.
risks.py
Added a
dash_core_components
import, necessary for instantiating the slider.Moved the creation of the
department
object, which is based on the GeoJSON local file for now, outside of thebuild_risks_geojson_and_colorbar
. I could not find any reason for which we would want to read the file each time we re-instantiate the colorbar and the GeoJSON objects. Especially since scores are still determined randomly for now - no refreshing issue.Variabilized the
opacity_level
in thebuild_risks_geojson_and_colorbar
.Wrote a function to instantiate the slider. It is an instantiation of the
dcc.Slider
, put inside a HTML div so that we can modify its width and eventually centred on the page.Added Markdown separators before and after the slider, in the part of the script where we define the layout of the page.
utils.py
Slightly reduced the map height to leave space for the slider. It is also useful for the "satellite" button in the alerts dashboard.