Conditional cell colour-coding and decimal formatting - can both work together?

Everything related to the development of modules in jamovi
Post Reply
GmA
Posts: 13
Joined: Wed Mar 19, 2025 3:23 pm

Conditional cell colour-coding and decimal formatting - can both work together?

Post by GmA »

Hello,

I'm developing a jamovi module (mentioned here: viewtopic.php?t=4082) and have been scratching my head for quite a while on the following.

I want to conditionally colour-code table cells based on threshold values (e.g., red for significant positive, blue for significant negative) and have the values respect jamovi's decimal formatting preferences.

What I've discovered:
Using table$addFormat(rowKey, col, "css-class-name") works for colour-coding, but only with type: text columns

However, text columns ignore jamovi's formatting system, so I must hardcode decimal places.

Using 'type: number', columns respects jamovi's formatting beautifully, but the CSS classes don't seem to apply

I've tried a few approaches (HTML spans, moving CSS files around, etc.) but keep hitting this same wall.

Question:
An I missing something obvious? How can I have conditional styling and native decimal formatting coexist in Jamovi ?

Happy to provide code examples if that would help.

Thanks,
Gianmarco
User avatar
jonathon
Posts: 2910
Joined: Fri Jan 27, 2017 10:04 am

Re: Conditional cell colour-coding and decimal formatting - can both work together?

Post by jonathon »

Hi Gianmarco,

Colour coding of values in table cells is something I don't think we've ever really made a priority of. so that there's any support for it at all is a bit of a surprise to me.

Having said that, it seems like something we could reasonably add.

Create an issue over on gh issues page, and we'll see what we can do. It's won't be a super-high priority of course, but we'll see.

https://github.com/jamovi/jamovi/issues

jonathon
GmA
Posts: 13
Joined: Wed Mar 19, 2025 3:23 pm

Re: Conditional cell colour-coding and decimal formatting - can both work together?

Post by GmA »

Hi Jonathon,

Thank you for the response! I may be misunderstanding something, but I'm a bit confused by your comment that colour-coding isn't really supported.

The screenshot I attached shows jamovi's built-in "Contingency Tables" analysis with the "Post Hoc Test (Pearson residuals)" option selected. The residual values in that table are clearly colour-coded - negative values appear in red (like -8.972 and -9.487) and positive values also in red (7.054 and 12.068).

This is precisely the behaviour I'm trying to replicate in my custom module - conditional colouring of numeric values based on thresholds whilst maintaining proper decimal formatting.

Is this colour-coding in the built-in analysis achieved through a different mechanism that isn't exposed to module developers? Or am I misunderstanding what you meant by colour-coding not being supported?

Sorry if I'm missing something obvious here!
Gianmarco
Attachments
Screenshot 2025-11-17 at 00.20.04.png
Screenshot 2025-11-17 at 00.20.04.png (336.07 KiB) Viewed 821 times
User avatar
MAgojam
Posts: 454
Joined: Thu Jun 08, 2017 2:33 pm
Location: Parma (Italy)

Re: Conditional cell colour-coding and decimal formatting - can both work together?

Post by MAgojam »

GmA wrote: Mon Nov 17, 2025 8:03 am The screenshot I attached shows jamovi's built-in "Contingency Tables" analysis with the "Post Hoc Test (Pearson residuals)" option selected. The residual values in that table are clearly colour-coded - negative values appear in red (like -8.972 and -9.487) and positive values also in red (7.054 and 12.068).
Ciao Gianmarco,
What you see in red is because I used Cell.NEGATIVE with the table's addFormat.
Take a look here:
https://github.com/jamovi/jmv/blob/mast ... #L833-L874

Saluti,
Maurizio
GmA
Posts: 13
Joined: Wed Mar 19, 2025 3:23 pm

Re: Conditional cell colour-coding and decimal formatting - can both work together?

Post by GmA »

Grazie Maurizio. I will look into that.

Cari saluti
Gm
User avatar
jonathon
Posts: 2910
Joined: Fri Jan 27, 2017 10:04 am

Re: Conditional cell colour-coding and decimal formatting - can both work together?

Post by jonathon »

> jamovi's built-in "Contingency Tables" analysis with the "Post Hoc Test (Pearson residuals)"

*chuckles*

i suppose i did add Cell.NEGATIVE, but that was a long time ago, and i didn't think we ever got around to using it.

maurizio did implement the post-hocs for the contingency tables, and he must of snuck this colour coding in without the rest of us noticing!

jonathon
Post Reply