plotly/dash-ag-grid

Ability to use python functions in condition parameter

safroze-plotly opened this issue · 2 comments

Example Use Case:
Consider the following scenario where a developer wishes to apply a style condition based on the output of a Python function:

json
Copy code
"styleConditions": [
{
"condition": "my_python_function(params.value) == 1",
"style": {"backgroundColor": "red"}
}
]

Hello @safroze-plotly,

This would be quite unlikely to happen.

The grid and the python environments are two completely different eco systems, in order to communicate back and forth on each row in a cell would be difficult, network intense, etc. The grid executes this function in JS, for each row.

We could possibly generate a converter, but it would be flakey at best, and the schema that you are providing wouldnt work for it.

My recommendation is for you to write the function in Python, get it working the way that you want it by updating the df, then make the condition like this: "condition": "params.data ? params.data.check_column == 1 : 0".

Or, you can convert your python function to JS yourself and have it on the clientside.

@safroze-plotly
This would be awesome if it was possible to do efficiently, since most Dash users code primarily in Python.

Here are a couple more tips for this:

Or, you can convert your python function to JS yourself and have it on the clientside.

  1. Feel free to ask on the Dash Community Forum. If you post a code snippet like above and include the python function, then someone is likely to help.

  2. ChatGPT - even the free 3.5 version is pretty good at converting simple Python functions to JavaScript. It's still flaky, so you have to verify it's answers, but it can save some time.