Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preconfig conditional format #1259

Merged
merged 26 commits into from
Mar 13, 2024
Merged

Preconfig conditional format #1259

merged 26 commits into from
Mar 13, 2024

Conversation

aarondr77
Copy link
Member

@aarondr77 aarondr77 commented Mar 11, 2024

Description

Preconfigure conditional formatting in a Streamlit / Enterprise app.

Testing

See the tests + use the sample app I created in streamlit/v1/apps

new_dfs, code = spreadsheet(
    df, 
    column_definitions=[
        [
            {
                'columns': ['A', 'B'],
                'conditional_formats': [{
                    'filters': [{'condition': 'greater_than_or_equal', 'value': 5}], 
                    'font_color': '#c30010', 
                    'background_color': '#ffcbd1' 
                }] 
            },
            {
                'columns': ['A'],
                'conditional_formats': [{
                    'filters': [{'condition': 'less', 'value': 2}], 
                    'font_color': '#f30010', 
                    'background_color': '#ddcbd1' 
                }] 
            }
        ],
        [
            # Add code here to style the second dataframe
        ]
    ]
)

Documentation

Note if any new documentation needs to addressed or reviewed.

Copy link

vercel bot commented Mar 11, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
monorepo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 13, 2024 1:40pm

@aarondr77
Copy link
Member Author

aarondr77 commented Mar 12, 2024

Should this be a preprocessing Step?

Because the preprocessing steps are particularly ordered (they rely on each other's previous results to create dataframes for the passed args and finally return the df_names and dataframe args) it doesn't make sense to treat this as the same sort of preprocessing step as it causes additional complexity that is not obvious by just reading the step_managers.

Not really sure what the advantage of it being a preprocessing step vs just something that happens in the setup of the steps manager. The second approach is cleaner cause there is infrastructure overhead like passing the args, df_names around, and setting the execution data...

Proposal

  1. Just make a function get_dataframe_formats_from_column_definititions(dfs: List[pd.DataFrame], column_definitions)
  2. Call this function after the preprocessing steps in the step performer.

This will give us more type safety, (we can actually pass the dfs as a list of dataframes to do additional validation of the column definitions), and make the order of operations obvious in the steps manager.

In addition, it's even kinda of weird to have this as a step performer because its just setting the df_formats step performer and not actually generating any code / comments, etc.

I don't think we gain anything by explicitly making this a preprocessing step, right?

Copy link
Contributor

@naterush naterush left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code is really clean and looks nice. LGTM once you fix up the minor review here!

@naterush
Copy link
Contributor

  1. Merge in dev to get tests passing
  2. Let's not forget to write docs

@aarondr77 aarondr77 merged commit a3c1b9e into dev Mar 13, 2024
62 checks passed
@marthacryan marthacryan deleted the preconfig-conditional-format branch March 13, 2024 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants