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

[🐛 BUG] style[column_name] does not render any color #1792

Closed
2 of 4 tasks
sumanth-tccc opened this issue Sep 16, 2024 · 9 comments
Closed
2 of 4 tasks

[🐛 BUG] style[column_name] does not render any color #1792

sumanth-tccc opened this issue Sep 16, 2024 · 9 comments
Assignees
Labels
🖰 GUI Related to GUI 🆘 Help wanted Open to participation from the community 💥Malfunction Addresses an identified problem. 🟥 Priority: Critical Must be addressed as soon as possible

Comments

@sumanth-tccc
Copy link

What went wrong? 🤔

<|{food_df}|table|style[Category] = {lambda state, value, index, row, column_name: "blue-cell"}|> when trying cell render no highlights seen

Expected Behavior

Expected column to highlight

Steps to Reproduce Issue

food_df = pd.DataFrame({
"Meal": ["Lunch", "Dinner", "Lunch", "Lunch", "Breakfast", "Breakfast", "Lunch", "Dinner"],
"Category": ["Food", "Food", "Drink", "Food", "Food", "Drink", "Dessert", "Dessert"],
"Name": ["Burger", "Pizza", "Soda", "Salad", "Pasta", "Water", "Ice Cream", "Cake"],
"Calories": [300, 400, 150, 200, 500, 0, 400, 500],
})

def food_df_on_edit(state, var_name, payload):
index = payload["index"] # row index
col = payload["col"] # column name
value = payload["value"] # new value cast to the column type
user_value = payload["user_value"] # new value as entered by the user

old_value = state.food_df.loc[index, col]
new_food_df = state.food_df.copy()
new_food_df.loc[index, col] = value
state.food_df = new_food_df
notify(state, "I", f"Edited value from '{old_value}' to '{value}'. (index '{index}', column '{col}')")

def food_df_on_delete(state, var_name, payload):
index = payload["index"] # row index

state.food_df = state.food_df.drop(index=index)
notify(state, "E", f"Deleted row at index '{index}'")

def food_df_on_add(state, var_name, payload):
empty_row = pd.DataFrame([[None for _ in state.food_df.columns]], columns=state.food_df.columns)
state.food_df = pd.concat([empty_row, state.food_df], axis=0, ignore_index=True)

notify(state, "S", f"Added a new row.")

def table_style(state, index, row):
return "blue-cell" if row.Category == "Dessert" else ""

def highlight_column_cells(state, value, index, row, column_name):
print(f"Column: {column_name}, Value: {value}, Row: {row}")

if row.Category == 'Dessert':
    return "blue-cell"
return ""

def simple_highlight(state, value, index, row, column_name):
return "blue-cell" # Apply to all cells as a test

table_properties = {
"class_name": "rows-bordered",
"filter": True,
"on_edit": food_df_on_edit,
"on_delete": food_df_on_delete,
"on_add": food_df_on_add,
"group_by[Category]": True,
"apply[Calories]": "sum",
"style[Calories]" : highlight_column_cells
}

Solution Proposed

No response

Screenshots

DESCRIPTION

Runtime Environment

No response

Browsers

No response

OS

No response

Version of Taipy

No response

Additional Context

No response

Acceptance Criteria

  • Ensure new code is unit tested, and check code coverage is at least 90%.
  • Create related issue in taipy-doc for documentation and Release Notes.

Code of Conduct

  • I have checked the existing issues.
  • I am willing to work on this issue (optional)
@sumanth-tccc sumanth-tccc added the 💥Malfunction Addresses an identified problem. label Sep 16, 2024
@sumanth-tccc sumanth-tccc changed the title [🐛 BUG] <|{food_df}|table|style[Category] = {lambda state, value, index, row, column_name: "blue-cell"}|> does not render any color [🐛 BUG] style[column_name] does not render any color Sep 16, 2024
@jrobinAV jrobinAV added 🟥 Priority: Critical Must be addressed as soon as possible 🆘 Help wanted Open to participation from the community 🖰 GUI Related to GUI labels Sep 20, 2024
@FredLL-Avaiga FredLL-Avaiga self-assigned this Sep 23, 2024
@FredLL-Avaiga
Copy link
Member

FredLL-Avaiga commented Sep 23, 2024

<|{food_df}|table|style[Category] = {lambda state, value, index, row, column_name: "blue-cell"}|> works for me

Image

blue-cell class name is applied to every cell for the Category column

The blue-cell class has to be defined though.
Which can be done through the style parameter of Markdown.

page = Markdown("""
<|{food_df}|table|properties={table_properties}|style[Category] = {lambda state, value, index, row, column_name: "blue-cell"}|>
""", style={".blue-cell": {"background-color": "blue"}})
import pandas as pd

from taipy.gui import Gui, Markdown, notify

food_df = pd.DataFrame(
    {
        "Meal": ["Lunch", "Dinner", "Lunch", "Lunch", "Breakfast", "Breakfast", "Lunch", "Dinner"],
        "Category": ["Food", "Food", "Drink", "Food", "Food", "Drink", "Dessert", "Dessert"],
        "Name": ["Burger", "Pizza", "Soda", "Salad", "Pasta", "Water", "Ice Cream", "Cake"],
        "Calories": [300, 400, 150, 200, 500, 0, 400, 500],
    }
)


def food_df_on_edit(state, var_name, payload):
    index = payload["index"]  # row index
    col = payload["col"]  # column name
    value = payload["value"]  # new value cast to the column type
    user_value = payload["user_value"]  # new value as entered by the user

    old_value = state.food_df.loc[index, col]
    new_food_df = state.food_df.copy()
    new_food_df.loc[index, col] = value
    state.food_df = new_food_df
    notify(state, "I", f"Edited value from '{old_value}' to '{value}'. (index '{index}', column '{col}')")


def food_df_on_delete(state, var_name, payload):
    index = payload["index"]  # row index

    state.food_df = state.food_df.drop(index=index)
    notify(state, "E", f"Deleted row at index '{index}'")


def food_df_on_add(state, var_name, payload):
    empty_row = pd.DataFrame([[None for _ in state.food_df.columns]], columns=state.food_df.columns)
    state.food_df = pd.concat([empty_row, state.food_df], axis=0, ignore_index=True)

    notify(state, "S", "Added a new row.")


def table_style(state, index, row):
    return "blue-cell" if row.Category == "Dessert" else ""


def highlight_column_cells(state, value, index, row, column_name):
    print(f"Column: {column_name}, Value: {value}, Row: {row}")

    if row.Category == "Dessert":
        return "blue-cell"
    return ""


def simple_highlight(state, value, index, row, column_name):
    return "blue-cell"  # Apply to all cells as a test


table_properties = {
    "class_name": "rows-bordered",
    "filter": True,
    "on_edit": food_df_on_edit,
    "on_delete": food_df_on_delete,
    "on_add": food_df_on_add,
    "group_by[Category]": True,
    "apply[Calories]": "sum",
    "style[Calories]": highlight_column_cells,
}

page = Markdown("""
<|{food_df}|table|properties={table_properties}|style[Category] = {lambda state, value, index, row, column_name: "blue-cell"}|>
""", style={".blue-cell": {"background-color": "blue"}})

Gui(page).run(title="1792 table indexed style")

@FredLL-Avaiga
Copy link
Member

If you find the answer complete, I'll let you close this issue.

@sumanth-tccc
Copy link
Author

Hi Team,
Thanks for the support , I tried the same as above in a new .py file, tested different browser and private browsing. Still unable to get the render on columns., Please find the screenshot below
image

@FlorianJacta
Copy link
Member

This also doesn't work for me on 3.1.1 and 4.0.0.dev2.

@FredLL-Avaiga
Copy link
Member

sorry then, it must only be in develop

@FredLL-Avaiga
Copy link
Member

can you check if the blue-cell class is applied or not (ie present in the class attribute of the relevant TD) ?

@FlorianJacta
Copy link
Member

I also put the blue-cell class in my css without any result

@sumanth-tccc
Copy link
Author

Did add the blue-cell class. Not rendering color on columns. Full rows are working fine.

@FredLL-Avaiga
Copy link
Member

Then you'll have to wait for the next release or request a developper release

@jrobinAV jrobinAV added hacktoberfest hacktoberfest issues hacktoberfest - 200💎💎 Issues rewarded by 200 points and removed hacktoberfest hacktoberfest issues hacktoberfest - 200💎💎 Issues rewarded by 200 points labels Sep 25, 2024
@jrobinAV jrobinAV closed this as completed Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🖰 GUI Related to GUI 🆘 Help wanted Open to participation from the community 💥Malfunction Addresses an identified problem. 🟥 Priority: Critical Must be addressed as soon as possible
Projects
None yet
Development

No branches or pull requests

4 participants