Quantcast
Channel: 🎛️ Dash - Plotly Community Forum
Viewing all articles
Browse latest Browse all 6271

Style_data_conditional and Empty Strings

$
0
0

Hi All, I’m new to Dash and Python so you know this is probably going to be a muppet post.

I have had a read of the 5 other posts similar to this one but none seem to address my problem apart from this one which was a bug back in 2019 and was addressed then.

I have Python 3.8.3, Dash 1.18.1 and dash-table 4.11.1

My Issue is that if i have a style_data_conditional filter set to highlight cells based on values

# Format Gross and Net Risk ***************************
# Cells dependant on risk score ***********************
#|------------|------------------|---------|------------|
#| Priority   | RGB Colour Value | Hex     |  Range     |
#|------------+------------------+---------+------------|
#| Very High  | 192, 0, 0        | #C00000 | > 18       |
#| High       | 237, 125, 49     | #ED7D31 | > 11 < 17  |
#| Medium     | 155, 192, 0      | #FFC000 | > 7 < 11   |
#| Low        | 0, 176, 80       | #00B050 | > 3 < 7    |
#| Very Low   | 146, 208, 80     | #92D050 | <= 3       |
#|------------|------------------|---------|------------|

I have filters for each of the Prioritys and they all work until I get to Very Low

# Format Gross and Net Risk ***************************
        # Cells dependant on risk score ***********************
        #|------------|------------------|---------|------------|
        #| Priority   | RGB Colour Value | Hex     |  Range     |
        #|------------+------------------+---------+------------|
        #| Very High  | 255, 0, 0        | #FF0000 | > 18       |
        #| High       | 255, 165, 0      | #FFA500 | > 11 < 17  |
        #| Medium     | 255, 255, 0      | #FFFF00 | > 7 < 11   |
        #| Low        | 154, 205, 50     | #9ACD32 | > 3 < 7    |
        #| Very Low   | 127, 255, 0      | #7FFF00 | <= 3       |
        #| Blank      | 255, 255, 255    | #FFFFFF | " "        |
        #|------------|------------------|---------|------------|

        # Very High - Gross Risk
        {
            'if': {
                'column_id': 'gross_risk',
                'filter_query': '{gross_risk} gt 16'
            },
            'backgroundColor': 'rgb(255, 0, 0)',
            'color': 'white',
            'font-size': 22,
            'textAlign': 'center',
        },

        # Very High - Net Risk
        {
            'if': {
                'column_id': 'net_risk',
                'filter_query': '{net_risk} gt 16'
            },
            'backgroundColor': 'rgb(255, 0, 0)',
            'color': 'white',
            'font-size': 22,
            'textAlign': 'center',
        },

        # High - Gross Risk
        {
            'if': {
                'column_id': 'gross_risk',
                'filter_query': '{gross_risk} gt 11 && {gross_risk} lt 17'
            },
            'backgroundColor': 'rgb(255, 165, 0)',
            'color': 'white',
            'font-size': 22,
            'textAlign': 'center',
        },

        # High - Net Risk
        {
            'if': {
                'column_id': 'net_risk',
                'filter_query': '{net_risk} gt 11 && {net_risk} lt 17'
            },
            'backgroundColor': 'rgb(255, 165, 0)',
            'color': 'white',
            'font-size': 22,
            'textAlign': 'center',
        },

        # Medium - Gross Risk
        {
            'if': {
                'column_id': 'gross_risk',
                'filter_query': '{gross_risk} gt 7 && {gross_risk} lt 11'
            },
            'backgroundColor': 'rgb(255, 255, 0)',
            'color': 'white',
            'font-size': 22,
            'textAlign': 'center',
        },

        # Medium - Net Risk
        {
            'if': {
                'column_id': 'net_risk',
                'filter_query': '{net_risk} gt 7 && {net_risk} lt 11'
            },
            'backgroundColor': 'rgb(255, 255, 0)',
            'color': 'white',
            'font-size': 22,
            'textAlign': 'center',
        },

        # Low - Gross Risk
        {
            'if': {
                'column_id': 'gross_risk',
                'filter_query': '{gross_risk} gt 3 && {gross_risk} lt 7'
            },
            'backgroundColor': 'rgb(154, 205, 50)',
            'color': 'white',
            'font-size': 22,
            'textAlign': 'center',
        },

        # Low - Net Risk
        {
            'if': {
                'column_id': 'net_risk',
                'filter_query': '{net_risk} gt 3 && {net_risk} lt 7'
            },
            'backgroundColor': 'rgb(154, 205, 50)',
            'color': 'white',
            'font-size': 22,
            'textAlign': 'center',
        },

        # Very Low - Gross Risk
        {
            'if': {
                'column_id': 'gross_risk',
                'filter_query': '{gross_risk} lt 4 && {net_risk} eq " "'
            },
            'backgroundColor': 'rgb(127, 255, 0)',
            'color': 'white',
            'font-size': 22,
            'textAlign': 'center',
        },

        # Very Low - Net Risk
        {
            'if': {
                'column_id': 'net_risk',
                'filter_query': '{net_risk} lt 4 && {net_risk} eq " "'
            },
            'backgroundColor': 'rgb(127, 255, 0)',
            'color': 'black',
            'font-size': 22,
            'textAlign': 'center',
        },

        # Empty Cell - Gross Risk
        {
            'if': {
                'column_id': 'gross_risk',
                'filter_query': '{gross_risk} eq " "'
            },
            'backgroundColor': 'rgb(255, 255, 255)',
            'color': 'black',
        },

        # Empty Cell - Net Risk
        {
            'if': {
                'column_id': 'net_risk',
                'filter_query': '{net_risk} eq " "'
            },
            'backgroundColor': 'rgb(255, 255, 255)',
            'color': 'black',
        },

    ],

When i run this over my data table, not only do the cells with a value under 4 not get coloured but also blank cells also do not get a background colour added as can be seen in the output below.

image

I’m sure it is an easy fix but not as easy as just removing the ’ && {net_risk} eq “” ’ from the filter or putting a space between the ’ " " ’

All help gratefully received.

And yes, I have the same code for net_risk hence i dint post it all juts the very low one

4 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 6271

Trending Articles