0

I am using Jupyter to create a report file of an analysis I'm doing. At the end of each analysis I'll provide a summary of how many errors/irregularities the analysis has found. I was wondering if there is a way to dynamically change the font color based on the results. e.g. let's say we have a variable called "font_color" and we have a if statement that sets the variable to "Red" if there are errors and "Black" if there is none, now in Jupyter markdown set the color as:

In code cell:

font_color = *IF statement to define color*

In markdown cell:

<font color={{font_color}}>
 - Testing

I'm open to suggestions and if there is a better way to dynamically change font colors.

smci
  • 32,567
  • 20
  • 113
  • 146
Hooman
  • 1
  • 1

1 Answers1

2

Yes, in Jupyter notebooks you can use code to output markdown as well the standout and stderr channels. And also in Jupyter notebooks you can use HTML within the markdown to color code parts of text. Combining those, you could customize something like this for your report generation:

from IPython.display import Markdown, display
a = "Good"
if a == "Good":
    font_color="green"
else:
    font_color="red"
def printmd(string):
    display(Markdown(string))
printmd("Summary:")
printmd(f'**<font color={font_color}>Status for a.</font>**')

Also see here and here.

Wayne
  • 6,607
  • 8
  • 36
  • 93