With Excel, you can easily apply conditional formatting over cells:
Is there any chance you can do something like this with Shiny? I've gone through the tutorials, but this apparently is not covered.
For instance, I'd like to conditionally colour the perm
row in runExample("02_text")
:
I got cell colouring in Shiny
DataTables
, which I believe is jQuery under the hood, using this code below for theoptions
part of therenderDataTable
call:I defined a list of colour ranges, like "regular", "strict", etc and had them in this colouring_datatables function below:
You can conditionnal formatting your table using jQuery.
For example :
In
tbody tr td:nth-child(5)
I precisenth-child(5)
To loop on eachtd
of the 5th column only (perms).We need
session$onFlushed(function() { session$sendCustomMessage(type='jsCode', list(value = script)) })
because if you put the script in the head, it will be executed before the table output rendered and then nothing will be formatting.If you want more formatting I suggest you to create css classes and use
addClass
:Take a look at this related thread, which provides options for conditional formatting with cutoff points (with a similar approach to Julien's answer to this question).
Cross-posting from that thread: To achieve conditional formatting with gradients based on cell values (for instance, to produce a heat map within a data table) you can combined the above approach with the approach taken in this Jquery blog post.
Note that this example asks you to define a max and min manually, but you can also create an array of all of your values and dynamically find the min and max for your data: see step 1 in this post.
Borrowing from jdharrison's self contained example: