qgridnext icon indicating copy to clipboard operation
qgridnext copied to clipboard

Amazing Stuff

Open Lucid-Will opened this issue 11 months ago • 1 comments

First, awesome stuff. Thank you for picking this back up.

I was able to implement pretty easily and have things working as expected with the exception of a recurring error that's thrown in my environment.

Environment

  • Operating System: Microsoft Fabric spark notebook (similar to Synapse Spark notebook)
  • Python Version: 3.10
  • Apache Spark Version: 3.4.1
  • Python packages:
    • Name: qgridnext - Version: 2.0.0
    • Name: pandas - Version: 2.0.3
    • Name: ipywidgets - Version: 8.0.7

Description of Issue

  • What did you expect to happen?
    • Package functions as expected with the exception of a recurring error in the environment. It doesn't seem to negatively impact the expected output.
  • What happened instead?
    • See attached image for error

Reproduction Steps

  1. Launch notebook in Microsoft Fabric data engineering enviornment
  2. Paste provided code and execute
  3. Wait for error to begin prompting in notifications (will happen quite frequently) ...

What steps have you taken to resolve this already?

Isolated the issue in standalone notebook to reproduce ...

Anything else?

!pip install qgridnext -q
import pandas as pd
import ipywidgets as widgets
from IPython.display import display
import qgrid

# Set up grid options and column options as you provided
grid_options = {
    'fullWidthRows': True,
    'syncColumnCellResize': True,
    'forceFitColumns': True,
    'defaultColumnWidth': 150,
    'rowHeight': 28,
    'enableColumnReorder': False,
    'editable': True,
    'autoEdit': False,
    'explicitInitialization': True,
    'enableAddRow': True,
    'maxVisibleRows': 25,
    'minVisibleRows': 8,
    'sortable': True,
    'filterable': True,
    'highlightSelectedCell': False,
    'highlightSelectedRow': True
}

column_options = {
    'editable': True,
    'sortable': True,
    'resizable': True,
}

# Sample DataFrame
df = pd.DataFrame({
    'Category': ['A', 'B', 'A', 'C'],
    'Value': [10, 20, 30, 40]
})

# Create dropdown for filtering
category_dropdown = widgets.Dropdown(
    options=['All'] + list(df['Category'].unique()),
    value='All',
    description='Category:',
)

# Initialize QgridWidget
qgrid_widget = qgrid.show_grid(df, show_toolbar=True, grid_options=grid_options, column_options=column_options)

# Define a function to filter the grid based on the dropdown selection
def filter_grid(change):
    if change.new == 'All':
        qgrid_widget.df = df
    else:
        qgrid_widget.df = df[df['Category'] == change.new]

# Observe changes in dropdown to apply filters
category_dropdown.observe(filter_grid, names='value')

# Define a button and its callback function for confirming the selection
confirm_button = widgets.Button(description='Confirm Selection')

def on_confirm_button_clicked(b):
    selected_df = qgrid_widget.get_changed_df()
    display(selected_df)

confirm_button.on_click(on_confirm_button_clicked)

# Display the dropdown, grid widget, and button
display(category_dropdown)
display(qgrid_widget)
display(confirm_button)

image ...

Lucid-Will avatar Mar 07 '24 15:03 Lucid-Will