I wrote an enhanced table from_dataframe method; easy links, conditional styles

I have generalized some code I wrote to make links easier in tables. The code is on github and an example app is running on my site.

I am curious as to feedback. The main branch currently subclasses dbc.Table, which may not be something I’m supposed to do, and I got a weird zipimporter error when trying to use it after installation with setup.py. The monkeypatch branch tacks on a new class method enhanced_from_dataframe to dbc.Table; avoiding any subclassing. Both get the same effect.

Would love feedback or ideas or even open issues/PRs. Thanks!

1 Like

Very sweet @marcosh , and thanks for sharing! Any chance you could post some screenshots of examples?

@chriddyp Ah yes, screenhots are a good idea. I don’t seem to be able to edit the original post anymore. Here is a screenshot of the example app showing the final styled table. The links work come from a Company_HREF column that provides the links to Company and a cell_style_dict that looks like this:

def color_positive(val):

    if val > 0:
        return {'className': 'table-success'}
    elif val < 0:
        return {'className': "table-warning"}

cell_style_dict = {
    'Company': [
        (['Yahoo', 'Apple'], {
            'font-weight': 'bold'
        (['Oracle'], {
            'className': 'table-danger'
    lambda x: {
        'background-color': '#7FFFD4'
    } if x > 10 else {},
    lambda x: {
        'className': 'table-info'
    } if x.weekday() in [4, 6] else {},

The table itself is created using:

        columns=['Company', 'Date', 'Value', 'Value2']),

Beautiful, love the design! Great color choices