rstoolbox.utils.highlight

rstoolbox.utils.highlight(row, selection, color='yellow', text_color='black', bold=True, for_image=False)

Highlight rows in Jupyter Notebooks that match the given index.

Parameters:
  • row (Series) – Row to which the formating is applied (directly provided by diplay.apply)
  • selection (Union[Index, DataFrame]) – list() of indexes to highlight.
  • color (str) – CSS defined color name for the background.
  • text_color (str) – CSS defined color name for the text.
  • bold (bool) – Make text bold.
  • outfile (str) – If provided, generate an image with the table.
  • for_image (str) – If provided, makes some format changes to better show in an image.
Returns:

CSS properties for the cells.

Note

Make the html output into an image with wkhtmltopdf and its python wrapper imgkit. wkhtmltopdf installation depends on the operating system. While for linux it might work with get-apt or similar, here are some tips for the macOS installation. Then, one might make it with a call such as:

imgkit.from_string(df.style.apply(rstoolbox.utils.highlight, selection=topside,
                                  for_image=True, axis=1).render(),
                   'out.png')

Take notice of the use of the for_image attribute. You can try to add more CSS rules with pandas.Styler.set_table_styles(). This seems to work properly for td and th but not for table or tr.