Spaces:
Sleeping
Sleeping
import pandas as pd | |
import gradio as gr | |
# Creating a sample dataframe | |
def run(): | |
df = pd.DataFrame({ | |
"A" : ["Apparel & Accessories", "Home & Garden", "Health & Beauty", "Cameras & Optics", "Apparel & Accessories"], | |
"B" : [6, 2, 54, 3, 2], | |
"C" : [3, 20, 7, 3, 8], | |
"D" : [2, 3, 6, 2, 6], | |
"E" : [-1, 45, 64, 32, 23] | |
}) | |
df = df.style.applymap(color_num, subset=["E"]) | |
return df | |
def color_num(value) -> str: | |
color = "red" if value >= 0 else "green" | |
color_style = f"color: {color}" | |
return color_style | |
def handle_change(df): | |
return df | |
demo = gr.Blocks() | |
with demo: | |
gr.Textbox(f"{gr.__version__}") | |
a = gr.DataFrame(show_search="filter") | |
b = gr.Button("run") | |
b.click(run,outputs=a) | |
a.change(lambda x: print(x), inputs=a) | |
c = gr.DataFrame(show_search="search") | |
a.change(handle_change, inputs=a, outputs=c) | |
if __name__ == "__main__": | |
demo.launch() | |