Giter VIP home page Giter VIP logo

shiny_tables's Introduction

Bootstrap tables from DataFrames

A very early rough implementation for Python Shiny of my Dash Dataframe Tables package. See A Live Demo App Here.

Features

This enhanced_from_dataframe function creates bootstrap tables with some automatic features like links and conditional formatting.

  • Automatic Links It will automatically generate ui.tags.A wrappers around a column from a matched column in the same dataframe. The hyperlink column must match the column_name + a specific suffix. In the example to the right, the (hidden) link column is Company_HREF, using the default suffix.
  • Conditional Formatting Criteria can either be a list of tuples (match_list,style_dict) or a callable that returns the style dict if the condition is met. This allows for more complex condition formatting.
  • Any Callable can wrap a cell Pass a callable to the function to customize the content of any column. Turn it into a button, link, wrap it in any UI elements you can create in Shiny.

How to use

This is invoked with render.ui and outputting to a ui output:

        
def server(input, output, session):

    @output
    @render.ui
    def result():
        return enhanced_from_dataframe(
            df,
            markdown_columns=['markdown_example'],
            cell_style_dict=cell_style_dict,
            columns=['Company', 'Date', 'Value', 'Value2', 'markdown_example'])

The code below generates the conditional formatting you see. You can also add a specific bootstrap class by putting a class key in the "style" dictionary.

def color_positive(val):
    if val > 0:
        return {'class': 'table-success'}
    elif val < 0:
        return {'class': "table-danger"}


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

This code has a callable wrapper for the Company2 column:

def wrap_company(row, col_name):
    return experimental.ui.tooltip(
        ui.tags.button(row[col_name], ),
        f"This is a tool tip for {row[col_name]} that shows the link {row['Company_HREF']}"
    )

Screenshot 2023-08-19 at 7 56 56 PM

shiny_tables's People

Contributors

astrowonk avatar mikewlloyd avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

shiny_tables's Issues

make this a module?

Or at least, make a version that works like a module.

The output would just be ui, the server function would accept the dataframe? Might be a little more Shiny-appropriate.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.