plotly / dash-table

OBSOLETE: now part of https://github.com/plotly/dash
https://dash.plotly.com
MIT License
419 stars 74 forks source link

Built-in heatmap-style cell background colours #659

Open interrogator opened 4 years ago

interrogator commented 4 years ago

May 1, 2020 Update by @chriddyp - This is now possible with conditional formatting. See https://dash.plotly.com/datatable/conditional-formatting & https://community.plotly.com/t/datatable-conditional-formatting-documentation/38763. We're keeping this issue open for built-in heatmap formatting that doesn't require code-intensive conditional formatting constructs.

I use a combination of pandas and dash-table, as I guess many do.

pandas can output tables to HTML. In addition, they've made it possible that you can pass in colourmaps, which, in combination with a cell's numerical content, can be used to make a simple heatmap. Example from the docs

colormap

I believe that something like this would already be possible using datatable, by comparing cell contents to a colourmap and using these to derive a background colour. (I wonder if anyone has a recipe for this?)

Even so, I think this would make a nice feature for the datatable, since you could in many ways copy the implementation inside pandas, background_gradient or cmap or whatever during instantiation of the datatable. If not, a recipe using conditional styling would still be great.

There was support for heatmaps here, but the issue ended after conditional formatting was added.

Marc-Andre-Rivet commented 4 years ago

@interrogator Thanks for the feedback. This can currently be done through the conditional formatting, but you are right that it's neither as nice, performant, or flexible as real native heatmaps support. While there's been some background discussions about this in the last few months, there's currently no timeline for supporting this feature.

chriddyp commented 4 years ago

@interrogator as a workaround, check out the heatmap chart type in plotly too: https://plot.ly/python/heatmaps/ There is a figure factory that generates a heatmap with nicely formatted text as well: https://plot.ly/python/annotated_heatmap/

interrogator commented 4 years ago

Thanks for the feedback. @chriddyp I already do use the plotly heatmap, it works well, but I do also have some data tables that could also benefit. @Marc-Andre-Rivet, yes, I suppose I'll do it via conditional formatting, probably just by copying how pandas does it, their result looks nice. Will post recipe if I do.

chriddyp commented 4 years ago

@interrogator et al - I just published some recipes on how to do this in the conditional formatting chapter: https://dash.plotly.com/datatable/conditional-formatting & https://community.plotly.com/t/datatable-conditional-formatting-documentation/38763.

There are ways we could make this easier & faster going forward, but this should work for now. 🥂

Rom2BE commented 1 year ago

@interrogator et al - I just published some recipes on how to do this in the conditional formatting chapter: https://dash.plotly.com/datatable/conditional-formatting & https://community.plotly.com/t/datatable-conditional-formatting-documentation/38763.

There are ways we could make this easier & faster going forward, but this should work for now. 🥂

Please note some examples are failing on https://dash.plotly.com/datatable/conditional-formatting For example: Highlighting a Range of Values