### PyPI Upload Success Output Example Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/RELEASE.md This is an example of the expected output when the `twine upload dist/*` command is successful. It shows the progress of uploading the wheel and tarball files and provides a link to the newly published version on PyPI. ```bash Uploading ipydatagrid-1.0.x-py3-none-any.whl 100%|████████████████████████████████████████████████████████████████████████████████████████████| 3.38M/3.38M [00:04<00:00, 720kB/s] Uploading ipydatagrid-1.0.x.tar.gz 100%|███████████████████████████████████████████████████████████████████████████████████████████| 22.4M/22.4M [00:07<00:00, 3.22MB/s] View at: https://pypi.org/project/ipydatagrid/1.0.x/ ``` -------------------------------- ### Monokai Theme Example Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/examples/Themes.ipynb This example demonstrates how to apply a Monokai-based theme to ipydatagrid using only top-level grid styling attributes. ```APIDOC ## Monokai-based theme for dark backgrounds Using only top-level grid styling without custom renderers ```python import pandas as pd import numpy as np import ipydatagrid as grid np.random.seed(104) rang = 10 df = pd.DataFrame( data=[np.random.randint(0, 11, rang) for i in range(rang)], index=[f"Row {i}" for i in range(rang)], columns=[f"Col {i}" for i in range(rang)], ) g = grid.DataGrid( df, layout={"height": "300px", "width": "800px"}, selection_mode="cell" ) g monokai = { "background_color": "#2c292d", "grid_line_color": "#a698eb7a", "header_background_color": "#2c292d9a", "header_grid_line_color": "#fc98675a", "selection_fill_color": "#78dce81a", "selection_border_color": "#ffd866", "header_selection_fill_color": "#ab9df24a", "header_selection_border_color": "lawngreen", "cursor_fill_color": "#78dce87a", "cursor_border_color": "#ff6188", } g.grid_style = monokai ``` ``` -------------------------------- ### Initialize DataGrid with Auto-Fit Columns Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/examples/Column Width Auto-Fit.ipynb Demonstrates initializing an ipydatagrid DataGrid with a pandas DataFrame and setting up auto-fitting for columns. This code snippet shows the initial setup and the default representation of the DataGrid. ```python import numpy as np import pandas as pd from ipydatagrid import DataGrid df = pd.DataFrame( data={ "Col1HasAVeryLongName": [1, 2, 4], "Col2MediumName": [4, 5, 6], "Col3": [7, 8, 9], } ) grid = DataGrid(df, index_name="index_column", layout={"height": "90px"}) grid ``` -------------------------------- ### Initialize DataGrid with Pandas DataFrame (Python) Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/ui-tests-ipw8/tests/notebooks/empty.ipynb This snippet shows the basic setup for creating a DataGrid. It imports necessary libraries, defines a Pandas DataFrame, and then initializes the DataGrid with this DataFrame. No external dependencies beyond ipydatagrid and pandas are required for this basic initialization. ```python from ipydatagrid import DataGrid, TextRenderer, BarRenderer, Expr, ImageRenderer import pandas as pd columns = ["a", "b", "c"] df = pd.DataFrame(dict(zip(columns, len(columns) * [[]]))) DataGrid(df) ``` -------------------------------- ### Upload ipydatagrid to PyPI using Twine Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/RELEASE.md This snippet demonstrates how to upload the built Python distribution files to the Python Package Index (PyPI) using the `twine` tool. Ensure `twine` is installed and you have the necessary upload credentials for the ipydatagrid package. ```bash pip install twine twine upload dist/* ``` -------------------------------- ### Cotton Candy Theme Example Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/examples/Themes.ipynb This example demonstrates how to apply a Cotton Candy theme to ipydatagrid using only top-level grid styling attributes. ```APIDOC ## Cotton candy theme for light backgrounds ```python cotton_candy = { "background_color": "rgb(255, 245, 251)", "header_background_color": "rgb(207, 212, 252, 1)", "header_grid_line_color": "rgb(0, 247, 181, 0.9)", "vertical_grid_line_color": "rgb(0, 247, 181, 0.3)", "horizontal_grid_line_color": "rgb(0, 247, 181, 0.3)", "selection_fill_color": "rgb(212, 245, 255, 0.3)", "selection_border_color": "rgb(78, 174, 212)", "header_selection_fill_color": "rgb(212, 255, 239, 0.3)", "header_selection_border_color": "rgb(252, 3, 115)", "cursor_fill_color": "rgb(186, 32, 186, 0.2)", "cursor_border_color": "rgb(191, 191, 78)", } g.grid_style = cotton_candy ``` ``` -------------------------------- ### Custom Boolean Renderers Example Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/examples/BoolRenderer.ipynb This example demonstrates how to create and apply custom renderers to boolean columns in an ipydatagrid. It defines several functions to map boolean values to specific Font Awesome icons and colors, and then applies these renderers to a pandas DataFrame. ```APIDOC ## Custom Boolean Renderers Example ### Description This example demonstrates how to create and apply custom renderers to boolean columns in an ipydatagrid. It defines several functions to map boolean values to specific Font Awesome icons and colors, and then applies these renderers to a pandas DataFrame. ### Method N/A (This is a Python code example for setting up a DataGrid) ### Endpoint N/A ### Parameters N/A ### Request Example ```python import pandas as pd import numpy as np import json from ipydatagrid import DataGrid, TextRenderer, Expr n = 50_000 df = pd.DataFrame( { "Value 1": np.random.randn(n), "Value 2": np.random.randn(n), "Value 3": np.random.choice([True, False], n), "Value 4": np.random.choice([True, False], n), } ) # This returns the unicode value for specific font-awesome icons, # check-out this link for more icons: # https://fontawesome.com/v4.7.0/cheatsheet/ def bool_render_text1(cell): if cell.value > 0: return "\uf00c" # Check else: return "\uf00d" # Cross def bool_render_text2(cell): if cell.value > 0: return "\uf111" # Circle else: return " " def bool_render_text3(cell): if cell.value: return "\uf164" # Thumb up else: return "\uf165" # Thumb down def bool_render_text4(cell): if cell.value: return "\uf118" # Smile else: return "\uf119" # Frown def bool_render_color(cell): if cell.value > 0: return "#2fbd34" else: return "#b82538" common_args = { "font": "bold 14px fontawesome", "text_color": Expr(bool_render_color), "horizontal_alignment": "center", } renderers = { "Value 1": TextRenderer(text_value=Expr(bool_render_text1), **common_args), "Value 2": TextRenderer(text_value=Expr(bool_render_text2), **common_args), "Value 3": TextRenderer(text_value=Expr(bool_render_text3), **common_args), "Value 4": TextRenderer(text_value=Expr(bool_render_text4), **common_args), } display(df) DataGrid(df, base_row_size=30, base_column_size=150, renderers=renderers) ``` ### Response N/A (This is a Python code example for setting up a DataGrid) #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### DataGrid with Multi-level Index Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/ui-tests-ipw8/tests/notebooks/datagrid_nested_hierarchies.ipynb This example demonstrates how to create an ipydatagrid DataGrid from a pandas DataFrame with multi-level column and row indexes. ```APIDOC ## DataGrid with Multi-level Index ### Description This example demonstrates how to create an ipydatagrid DataGrid from a pandas DataFrame with multi-level column and row indexes. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ### Code Example ```python import numpy as np import pandas as pd import ipydatagrid as g np.random.seed(1) # merging of lower level row headers col_top_level = [ "VeryLongValueFactors", "VeryLongValueFactors", "Even Longer Momentum Factors", "Even Longer Momentum Factors", ] col_bottom_level = ["Factor_A", "Factor_B", "Factor_C", "Factor_D"] # Rows row_top_level = ["Sector 1", "Sector 1", "Sector 2", "Sector 2", "Sector 3"] row_bottom_level = ["Security A", "Security B", "Security C", "Security C", "Security C"] nested_df = pd.DataFrame( np.random.randn(5, 4).round(4), columns=pd.MultiIndex.from_arrays([col_top_level, col_bottom_level]), index=pd.MultiIndex.from_arrays( [row_top_level, row_bottom_level], names=("Sector", "Ticker") ), ) nested_grid = g.DataGrid( nested_df, base_column_size=80, base_column_header_size=35, base_row_header_size=80, layout={"height": "180px"} ) nested_grid ``` ``` -------------------------------- ### Create Release Branch and Bump Version with Git Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/RELEASE.md This snippet demonstrates how to create a new release branch using Git and then use `tbump` to increment the patch version. It includes commands for checking out a branch, installing tbump, bumping the version, committing changes, and pushing the branch to origin. ```bash git checkout -n release_1.0.x pip install tbump tbump --only-patch 1.0.x git commit -s -m "Release 1.0.x" git push -u origin release_1.0.x ``` -------------------------------- ### Build Python Package for ipydatagrid Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/RELEASE.md This command builds the Python distribution files (wheel and tarball) for the ipydatagrid package. It requires the `build` package to be installed and should be run from the root directory of the project. The output is placed in the `dist` folder. ```bash python -m build ``` -------------------------------- ### Customizing DataGrid with Renderers Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/ui-tests-ipw8/tests/notebooks/html_renderer.ipynb This example shows how to create and apply custom renderers to specific columns in an ipydatagrid. It uses pandas to create a DataFrame and then configures TextRenderer and HtmlRenderer for different columns to control their appearance and content display. ```APIDOC ## Customizing DataGrid with Renderers ### Description This example demonstrates how to use custom renderers, `TextRenderer` and `HtmlRenderer`, to format data within an `ipydatagrid.DataGrid`. It involves creating a pandas DataFrame and then defining specific renderers for columns to control text color, background color, alignment, and HTML rendering. ### Method Python code execution ### Endpoint N/A (Local execution) ### Parameters N/A ### Request Example ```python import pandas as pd from bqplot import ColorScale from ipydatagrid import DataGrid, TextRenderer, HtmlRenderer df = pd.DataFrame( { "Value 1": [1, 2, 3, 4, 5], "Value 2": '
  1. Item 1
  2. Item 2
  3. Item 3
', "Value 3": '

Bold Text

Italic Text

Underlined Text

Strikethrough Text

' } ) text_renderer = TextRenderer( text_color="black", background_color=ColorScale(min=-5, max=5) ) html_renderer = HtmlRenderer(text_color='blue', background_color='aliceblue', horizontal_alignment='right', vertical_alignment='bottom') renderers = { "Value 1": text_renderer, "Value 2": html_renderer, "Value 3": html_renderer, } DataGrid(df, renderers=renderers,base_row_size=140, base_column_size=100) ``` ### Response N/A (Visual output in a Jupyter environment) #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Conditional Cell Formatting with VegaExpr in Python Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/ui-tests-ipw7/tests/notebooks/conditional_formatting.ipynb Applies conditional background colors to cells in a DataGrid based on cell values and metadata using VegaExpr. This example demonstrates accessing nested data structures within cell values and metadata for dynamic formatting. ```python import pandas as pd from ipydatagrid import DataGrid, TextRenderer, VegaExpr df = pd.DataFrame( { "column 1": [{"key": 11}, ["berry", "apple", "cherry"]], "column 2": [["berry", "berry", "cherry"], {"key": 10}], } ) renderer = TextRenderer( background_color=VegaExpr( "cell.value[1] == 'berry' && cell.metadata.data['column 1']['key'] == 11 ? 'limegreen' : 'pink'" ) ) DataGrid( df, layout={"height": "100px"}, base_column_size=150, default_renderer=renderer, ) ``` -------------------------------- ### Initialize DataGrid with Selection Mode Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/examples/Selections.ipynb Demonstrates how to import necessary libraries, load data into a pandas DataFrame, and instantiate a DataGrid with a specific selection mode. ```python from ipydatagrid import DataGrid from json import load import pandas as pd with open("./cars.json") as fobj: data = load(fobj) df = pd.DataFrame(data["data"]).drop("index", axis=1) datagrid = DataGrid(df, selection_mode="cell") datagrid ``` -------------------------------- ### Initialize DataGrid with Custom Renderers Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/examples/DataGrid.ipynb Demonstrates how to define column-specific renderers using TextRenderer and BarRenderer, incorporating Python functions and expressions for dynamic styling. ```python from bqplot import LinearScale, ColorScale, OrdinalColorScale, OrdinalScale from py2vega.functions.color import rgb def horsepower_coloring(cell): if cell.value < 100: return "red" elif cell.value < 150: return "orange" else: return "green" def weight_coloring(cell): scaled_value = 1 if cell.value > 4500 else cell.value / 4500 color_value = scaled_value * 255 return rgb(color_value, 0, 0) renderers = { "Acceleration": BarRenderer( horizontal_alignment="center", bar_color=ColorScale(min=0, max=20, scheme="viridis"), bar_value=LinearScale(min=0, max=20), ), "Cylinders": TextRenderer( background_color=Expr('"grey" if cell.row % 2 else default_value') ), "Horsepower": TextRenderer( text_color="black", background_color=Expr(horsepower_coloring) ), "Weight_in_lbs": TextRenderer( text_color="black", background_color=Expr(weight_coloring) ) } datagrid = DataGrid(df, renderers=renderers) ``` -------------------------------- ### POST /datagrid/initialize Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/ui-tests-ipw7/tests/notebooks/datagrid.ipynb Initializes a new DataGrid instance with a Pandas DataFrame, custom renderers, and initial layout configurations. ```APIDOC ## POST /datagrid/initialize ### Description Creates a new DataGrid widget instance bound to a provided Pandas DataFrame, allowing for custom cell rendering and layout sizing. ### Method POST ### Endpoint /datagrid/initialize ### Parameters #### Request Body - **df** (DataFrame) - Required - The source data to display. - **base_row_size** (int) - Optional - Default height of rows in pixels. - **base_column_size** (int) - Optional - Default width of columns in pixels. - **renderers** (dict) - Optional - Mapping of column names to renderer objects (e.g., TextRenderer, BarRenderer). ### Request Example { "df": "", "base_row_size": 30, "base_column_size": 300, "renderers": { "Value 1": "TextRenderer", "Dates": "BarRenderer" } } ### Response #### Success Response (200) - **grid** (Object) - The initialized DataGrid widget instance. #### Response Example { "status": "success", "grid_id": "uuid-12345" } ``` -------------------------------- ### Initialize a Basic DataGrid Source: https://context7.com/jupyter-widgets/ipydatagrid/llms.txt Demonstrates how to instantiate a DataGrid widget using a pandas DataFrame and configure basic layout properties such as row size, column size, and selection modes. ```python from ipydatagrid import DataGrid import pandas as pd df = pd.DataFrame({ "Name": ["Alice", "Bob", "Charlie", "Diana"], "Age": [25, 30, 35, 28], "Score": [85.5, 92.3, 78.9, 88.1], "Department": ["Engineering", "Marketing", "Engineering", "Sales"] }) grid = DataGrid( df, base_row_size=30, base_column_size=120, base_row_header_size=64, base_column_header_size=20, header_visibility="all", selection_mode="cell", editable=False, auto_fit_columns=True, horizontal_stripes=True, layout={"height": "300px"} ) grid ``` -------------------------------- ### POST /datagrid/initialize Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/examples/Pandas.ipynb Initializes a new DataGrid instance with a pandas DataFrame and custom renderers. ```APIDOC ## POST /datagrid/initialize ### Description Creates a new DataGrid widget instance bound to a provided dataset and configuration for cell rendering. ### Method POST ### Endpoint /datagrid/initialize ### Parameters #### Request Body - **data** (object) - Required - The pandas DataFrame or equivalent data structure - **base_row_size** (integer) - Optional - Default height of rows - **base_column_size** (integer) - Optional - Default width of columns - **renderers** (object) - Optional - Mapping of column names to renderer instances ### Request Example { "base_row_size": 30, "base_column_size": 300, "renderers": { "Value 1": "TextRenderer", "Dates": "BarRenderer" } } ### Response #### Success Response (200) - **grid_id** (string) - Unique identifier for the created DataGrid instance #### Response Example { "grid_id": "dg_001" } ``` -------------------------------- ### Configure Grid Layout and Selection Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/ui-tests-ipw7/tests/notebooks/datagrid_nested_hierarchies_update.ipynb Demonstrates how to enable auto-fit column sizing, update base column sizes, and manage cell selections programmatically. ```python nested_grid.auto_fit_columns = True nested_grid.base_column_size = 79 nested_grid.selection_mode = "cell" nested_grid.select(2, 3) nested_grid.selections = [] ``` -------------------------------- ### Initialize DataGrid with Conditional Rendering Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/ui-tests-ipw8/tests/notebooks/conditional_formatting.ipynb Demonstrates how to create a DataGrid and apply a TextRenderer with conditional background colors based on cell values and metadata using Vega expressions. ```APIDOC ## DataGrid Initialization with VegaExpr ### Description Initializes a DataGrid with a pandas DataFrame and applies a custom TextRenderer that uses Vega expressions to dynamically set cell background colors based on cell values and metadata. ### Method Constructor (Python Class) ### Parameters #### Request Body - **df** (pd.DataFrame) - Required - The source data to display. - **layout** (dict) - Optional - CSS layout properties for the grid. - **base_column_size** (int) - Optional - Default width of columns. - **default_renderer** (TextRenderer) - Optional - The renderer instance for cell styling. ### Request Example ```python renderer = TextRenderer( background_color=VegaExpr("cell.value[1] == 'berry' && cell.metadata.data['column 1']['key'] == 11 ? 'limegreen' : 'pink'") ) DataGrid(df, layout={"height": "100px"}, default_renderer=renderer) ``` ### Response #### Success Response (200) - **DataGrid** (Object) - Returns an interactive grid widget instance. ``` -------------------------------- ### Initialize DataGrid with Custom Renderers Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/examples/HtmlRenderer.ipynb This snippet demonstrates how to prepare a pandas DataFrame, define Text and HTML renderers with specific styling, and instantiate a DataGrid widget. The DataGrid maps columns to renderers to control the visual presentation of the data. ```python import pandas as pd from bqplot import ColorScale from ipydatagrid import DataGrid, TextRenderer, HtmlRenderer df = pd.DataFrame({ "Value 1": [1, 2, 3, 4, 5], "Value 2": '
  1. Item 1
  2. Item 2
  3. Item 3
', "Value 3": '

Bold Text

' }) text_renderer = TextRenderer(text_color="black", background_color=ColorScale(min=-5, max=5)) html_renderer = HtmlRenderer(text_color='blue', background_color='aliceblue', horizontal_alignment='right', vertical_alignment='bottom') renderers = { "Value 1": text_renderer, "Value 2": html_renderer, "Value 3": html_renderer } grid = DataGrid(df, renderers=renderers, base_row_size=140, base_column_size=100) grid ``` -------------------------------- ### Create and Display DataGrid with Custom Renderers and Sorting (Python) Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/examples/Pandas.ipynb This snippet demonstrates how to create a pandas DataFrame, define custom renderers for columns (TextRenderer and BarRenderer with date-based conditional coloring), initialize a DataGrid, and apply a sort transformation. It requires libraries like pandas, numpy, bqplot, and ipydatagrid. ```python import json import numpy as np import pandas as pd from bqplot import DateScale, ColorScale from py2vega.functions.type_coercing import toDate from py2vega.functions.date_time import datetime from ipydatagrid import Expr, DataGrid, TextRenderer, BarRenderer n = 10000 df = pd.DataFrame( { "Value 1": np.random.randn(n), "Value 2": np.random.randn(n), "Dates": pd.date_range(end=pd.Timestamp("today"), periods=n), } ) text_renderer = TextRenderer( text_color="black", background_color=ColorScale(min=-5, max=5) ) def bar_color(cell): date = toDate(cell.value) return "green" if date > datetime("2000") else "red" renderers = { "Value 1": text_renderer, "Value 2": text_renderer, "Dates": BarRenderer( bar_value=DateScale(), bar_color=Expr(bar_color), format="%Y/%m/%d", format_type="time", ), } grid = DataGrid(df, base_row_size=30, base_column_size=300, renderers=renderers) grid.transform([{"type": "sort", "column": "Dates", "desc": True}]) grid ``` -------------------------------- ### POST /widgets/datagrid Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/examples/HtmlRenderer.ipynb Initializes a new DataGrid widget instance with specific data, custom renderers, and dimension settings. ```APIDOC ## POST /widgets/datagrid ### Description Creates a new DataGrid instance to display Pandas DataFrames with custom cell rendering capabilities. ### Method POST ### Endpoint /widgets/datagrid ### Parameters #### Request Body - **df** (DataFrame) - Required - The source Pandas DataFrame to display. - **renderers** (Dict) - Optional - Mapping of column names to renderer instances (e.g., TextRenderer, HtmlRenderer). - **base_row_size** (Integer) - Optional - Default height for rows in pixels. - **base_column_size** (Integer) - Optional - Default width for columns in pixels. ### Request Example { "df": "pd.DataFrame({...})", "renderers": {"Value 1": "TextRenderer", "Value 2": "HtmlRenderer"}, "base_row_size": 140, "base_column_size": 100 } ### Response #### Success Response (200) - **grid** (DataGrid) - The initialized DataGrid widget object. #### Response Example { "status": "success", "widget_id": "DataGrid-001" } ``` -------------------------------- ### Configure TextRenderer with wrapping and conditional styling Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/examples/Text Wrapping and Eliding.ipynb Demonstrates how to initialize TextRenderer instances for grid cells and headers. It covers setting text wrapping, alignment, eliding directions, and using Vega expressions for dynamic background colors. ```python import ipydatagrid as grid import pandas as pd import numpy as np np.random.seed(98) data = pd.DataFrame( columns=["Many Words In This Column", "SingleWordColumn"], data=np.random.random_sample((5, 2)), ) default_renderer = grid.TextRenderer( background_color=grid.VegaExpr("cell.value <= 0.5 ? 'pink' : 'lawngreen'"), text_elide_direction="left", ) header_renderer = grid.TextRenderer( text_color="navy", text_wrap=True, vertical_alignment="top", background_color="moccasin", horizontal_alignment="center", ) grid.DataGrid( data, base_column_size=90, base_column_header_size=35, base_row_header_size=80, layout={"height": "180px"}, header_renderer=header_renderer, default_renderer=default_renderer, ) ``` -------------------------------- ### Initialize Multi-Indexed DataGrid with Custom Renderers Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/ui-tests-ipw8/tests/notebooks/datagrid_nested_hierarchies_update.ipynb Creates a DataGrid using a pandas DataFrame with MultiIndex columns and rows. It demonstrates applying custom TextRenderer configurations for headers and cell values using Vega expressions. ```python import ipydatagrid as g import pandas as pd import numpy as np nested_df = pd.DataFrame( np.random.randn(4, 4).round(4), columns=pd.MultiIndex.from_arrays([["A", "A", "B", "B"], ["F1", "F2", "F3", "F4"]]), index=pd.MultiIndex.from_arrays([["S1", "S1", "S2", "S2"], ["T1", "T2", "T3", "T4"]]) ) header_renderer = g.TextRenderer(background_color="moccasin", text_color="navy") default_renderer = g.TextRenderer(text_color=g.VegaExpr("cell.value <= 0 ? 'purple' : 'green'")) nested_grid = g.DataGrid(nested_df, header_renderer=header_renderer, default_renderer=default_renderer) ``` -------------------------------- ### Create DataGrid with MultiIndex Columns Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/examples/ConditionalFormatting.ipynb Demonstrates how to initialize a DataGrid using a pandas DataFrame with a MultiIndex, useful for hierarchical data representation. ```python import ipydatagrid as ipg import pandas as pd import numpy as np top_level = [ "Value Factors", "Value Factors", "Momentum Factors", "Momentum Factors", ] bottom_level = ["Factor A", "Factor B", "Factor C", "Factor D"] nested_df = pd.DataFrame( np.random.randn(4, 4).round(2), columns=pd.MultiIndex.from_arrays([top_level, bottom_level]), index=pd.Index( ["Security {}".format(x) for x in ["A", "B", "C", "D"]], name="Ticker" ), ) ``` -------------------------------- ### Apply Data Transformations Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/examples/DataGrid.ipynb Shows how to apply filtering and sorting transformations to an existing DataGrid instance. ```python datagrid.transform([ {"type": "filter", "operator": "=", "column": "Origin", "value": "USA"}, {"type": "filter", "operator": "<", "column": "Horsepower", "value": 130}, {"type": "sort", "column": "Acceleration"} ]) ``` -------------------------------- ### Create and Configure HyperlinkRenderer in Python Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/examples/HyperlinkRenderer.ipynb This snippet demonstrates how to create a pandas DataFrame and then configure a DataGrid with a HyperlinkRenderer. The renderer is set up to display a URL and a corresponding display name from the DataFrame's cell values, with custom styling applied. Links are opened by Ctrl/Command-clicking. ```python import pandas as pd import numpy as np from ipydatagrid import VegaExpr, DataGrid, TextRenderer, HyperlinkRenderer df = pd.DataFrame( data={ "Name": ["NumFocus"], "Link": [["https://numfocus.org/", "Better tools to build a better worlds."]], } ) link_renderer = HyperlinkRenderer( url=VegaExpr("cell.value[0]"), url_name=VegaExpr("cell.value[1]"), background_color="moccasin", text_color="blue", font="bold 14px Arial, sans-serif", ) grid = DataGrid( df, layout={"height": "120px"}, base_column_size=200, renderers={"Link": link_renderer}, ) grid ``` -------------------------------- ### Apply Data Transforms and Filters Source: https://context7.com/jupyter-widgets/ipydatagrid/llms.txt Demonstrates how to apply multiple data transformations including filtering and sorting to an ipydatagrid instance. It also shows how to revert changes and retrieve the processed visible data. ```python grid.transform([ {"type": "filter", "column": "Price", "operator": "<", "value": 3.0}, {"type": "sort", "column": "Stock", "desc": True} ]) grid.transform([ {"type": "filter", "column": "Price", "operator": "between", "value": [1.0, 3.0]}, {"type": "filter", "column": "Stock", "operator": ">=", "value": 50}, {"type": "sort", "column": "Product"} ]) grid.revert() visible_df = grid.get_visible_data() print(visible_df) ``` -------------------------------- ### Configure Column Widths in DataGrid Source: https://context7.com/jupyter-widgets/ipydatagrid/llms.txt Shows how to set column widths manually using the 'column_widths' parameter or automatically adjust them using 'auto_fit_columns'. The 'auto_fit_params' allow fine-tuning of the auto-fitting behavior. ```python from ipydatagrid import DataGrid import pandas as pd df = pd.DataFrame({ "ID": [1, 2, 3], "Name": ["A very long product name here", "Short", "Medium length"], "Price": [1234567.89, 42.00, 999.99], "Description": ["Lorem ipsum dolor sit amet", "Brief", "Some text"] }) # Manual column widths grid = DataGrid( df, column_widths={ "ID": 50, "Name": 250, "Price": 120, "Description": 200 }, layout={"height": "150px"} ) # Or use auto-fit columns grid_autofit = DataGrid( df, auto_fit_columns=True, auto_fit_params={ "area": "all", # 'all', 'body', 'row-header' "padding": 30, # Extra padding in pixels "numCols": None # Limit number of columns to resize (None = all) }, layout={"height": "150px"} ) grid_autofit ``` -------------------------------- ### Create and Activate Conda Environment for Release Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/RELEASE.md This snippet shows how to create a dedicated conda environment for the release process, ensuring a clean and reproducible build environment. It specifies Python version and necessary build tools. ```bash conda create -n release_grid -c conda-forge python=3.8 python-build conda activate release_grid ``` -------------------------------- ### Advanced Bar and Text Rendering with Date Logic Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/examples/ConditionalFormatting.ipynb Illustrates complex rendering scenarios including BarRenderer with DateScale and conditional formatting based on date comparisons. It uses py2vega helper functions to process date values within the grid. ```python def format_based_on_date(cell): return ( "magenta" if cell.column == 0 and cell.metadata.data["Dates"] >= "2020-10-21" else "yellow" ) def bar_color(cell): date = toDate(cell.value) return "green" if date > datetime("2000") else "red" renderers = { "Value 1": TextRenderer(text_color="black", background_color=Expr(format_based_on_date)), "Dates": BarRenderer( bar_value=DateScale(), bar_color=Expr(bar_color), format="%Y/%m/%d", format_type="time", ), } ``` -------------------------------- ### Initialize Multi-Indexed DataGrid Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/ui-tests-ipw7/tests/notebooks/datagrid_nested_hierarchies_update.ipynb Creates a DataGrid with multi-level columns and rows using pandas MultiIndex. It includes custom header and cell renderers for visual styling. ```python import ipydatagrid as g import pandas as pd import numpy as np nested_df = pd.DataFrame( np.random.randn(4, 4).round(4), columns=pd.MultiIndex.from_arrays([["V", "V", "E", "E"], ["A", "B", "C", "D"]]), index=pd.MultiIndex.from_arrays([["S1", "S1", "S2", "S2"], ["A", "B", "C", "D"]]) ) header_renderer = g.TextRenderer(background_color="moccasin", text_color="navy") default_renderer = g.TextRenderer(text_color=g.VegaExpr("cell.value <= 0 ? 'purple' : 'green'")) nested_grid = g.DataGrid(nested_df, header_renderer=header_renderer, default_renderer=default_renderer) ``` -------------------------------- ### Grid Configuration and Styling Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/ui-tests-ipw7/tests/notebooks/datagrid_base_update.ipynb Endpoints and properties for managing grid layout, header visibility, and cell rendering. ```APIDOC ## SET grid.header_visibility ### Description Controls the visibility of row and column headers in the DataGrid. ### Parameters - **visibility** (string) - Required - Options: 'row', 'column', 'none', 'all' ### Request Example ```python grid.header_visibility = 'all' ``` ``` ```APIDOC ## SET grid.base_size_properties ### Description Configures the base pixel size for rows, columns, and headers. ### Parameters - **size** (int) - Required - Pixel value for the dimension. ### Request Example ```python grid.base_row_size = 50 grid.base_column_size = 128 grid.base_column_header_size = 60 ``` ``` ```APIDOC ## SET grid.renderers ### Description Assigns custom renderers to headers, corners, or specific data columns. ### Parameters - **renderer** (TextRenderer) - Required - The renderer instance to apply. ### Request Example ```python grid.header_renderer = g.TextRenderer(text_color='dodgerblue', background_color='navy') grid.default_renderer = g.TextRenderer(background_color='bisque') ``` ``` -------------------------------- ### Initialize StreamingDataGrid Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/examples/Streaming.ipynb How to instantiate a StreamingDataGrid with a pandas DataFrame and custom renderers. ```APIDOC ## StreamingDataGrid Initialization ### Description Initializes a new StreamingDataGrid instance to handle large datasets with lazy loading capabilities. ### Method Constructor ### Endpoint `ipydatagrid.StreamingDataGrid(dataframe, default_renderer=None, debounce_delay=50)` ### Parameters #### Request Body - **dataframe** (pd.DataFrame) - Required - The source data to be displayed. - **default_renderer** (Renderer) - Optional - Renderer instance for cell styling. - **debounce_delay** (int) - Optional - Delay in milliseconds for data requests. ### Request Example ```python streaming_datagrid = StreamingDataGrid(dataframe, default_renderer=default_renderer, debounce_delay=50) ``` ``` -------------------------------- ### Tagging and Pushing Release with Git Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/RELEASE.md This section details the Git commands for creating a new release tag, pushing it to the upstream repository, and pulling the latest changes from the main branch. This is crucial for marking a specific version for release. ```bash git checkout main && git pull upstream main git tag -a 1.0.x -m "Release 1.0.x" git push upstream --tags ``` -------------------------------- ### Configuring Multi-Index DataFrames Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/ui-tests-ipw8/tests/notebooks/conditional_formatting.ipynb Illustrates how to initialize an ipydatagrid with a pandas MultiIndex DataFrame to display hierarchical column headers. ```python import ipydatagrid as ipg import pandas as pd import numpy as np top_level = ["Value Factors", "Value Factors", "Momentum Factors", "Momentum Factors"] bottom_level = ["Factor A", "Factor B", "Factor C", "Factor D"] nested_df = pd.DataFrame( np.random.randn(4, 4).round(2), columns=pd.MultiIndex.from_arrays([top_level, bottom_level]), index=pd.Index(["Security {}".format(x) for x in ["A", "B", "C", "D"]], name="Ticker"), ) grid = ipg.DataGrid(nested_df) ``` -------------------------------- ### Customize Grid Styling and Theming Source: https://context7.com/jupyter-widgets/ipydatagrid/llms.txt Configures a custom dark theme for the DataGrid, including row striping using VegaExpr and scroll shadow settings. It also demonstrates how to apply custom renderers to headers, corners, and the body. ```python from ipydatagrid import DataGrid, TextRenderer, VegaExpr import pandas as pd import numpy as np df = pd.DataFrame(np.random.randint(0, 100, (10, 5)), columns=[f"Col {i}" for i in range(5)]) dark_theme = { "void_color": "#1e1e1e", "background_color": "#2d2d2d", "header_background_color": "#3d3d3d", "grid_line_color": "#555555", "header_grid_line_color": "#666666", "row_background_color": VegaExpr("cell % 2 === 0 ? '#2d2d2d' : '#353535'"), "scroll_shadow": {"size": 15, "color1": "rgba(0,0,0,0.3)", "color2": "rgba(0,0,0,0.15)", "color3": "rgba(0,0,0,0)"} } header_renderer = TextRenderer(background_color="#4a4a4a", text_color="#ffffff", font="bold 13px Arial") corner_renderer = TextRenderer(background_color="#5a5a5a", text_color="#cccccc") grid = DataGrid(df, grid_style=dark_theme, header_renderer=header_renderer, corner_renderer=corner_renderer) ``` -------------------------------- ### Custom Python-based Cell Rendering Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/ui-tests-ipw8/tests/notebooks/conditional_formatting.ipynb Shows how to define a custom Python function to determine cell styling dynamically. This is useful when logic is too complex for Vega expressions. ```python import numpy as np import pandas as pd from ipydatagrid import Expr, DataGrid, TextRenderer df = pd.DataFrame({"Column 0": np.random.randn(10), "Column 1": np.random.randn(10), "Column 2": np.random.randn(10)}) def format_based_on_other_column(cell): return "green" if cell.metadata.data["Column 2"] > 0.0 else "yellow" column1_formatting = TextRenderer( text_color="black", background_color=Expr(format_based_on_other_column), ) grid = DataGrid(df, renderers={"Column 1": column1_formatting}) ``` -------------------------------- ### DataGrid with Python-based Conditional Formatting Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/ui-tests-ipw8/tests/notebooks/conditional_formatting.ipynb Shows how to use a Python function within an Expr object to define custom rendering logic for specific columns in a DataGrid. ```APIDOC ## DataGrid with Python Expr ### Description Configures a DataGrid to use a Python function for conditional formatting, allowing for complex logic that evaluates sibling cell values. ### Method Constructor (Python Class) ### Parameters #### Request Body - **renderers** (dict) - Required - Mapping of column names to TextRenderer instances. ### Request Example ```python def format_based_on_other_column(cell): return "green" if cell.metadata.data["Column 2"] > 0.0 else "yellow" column1_formatting = TextRenderer(background_color=Expr(format_based_on_other_column)) renderers = {"Column 1": column1_formatting} DataGrid(df, renderers=renderers) ``` ### Response #### Success Response (200) - **DataGrid** (Object) - Returns a grid instance with column-specific formatting. ``` -------------------------------- ### Display DataGrid in Python Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/ui-tests-ipw8/tests/notebooks/datagrid.ipynb This snippet simply displays the previously configured DataGrid object in a Python environment, likely a Jupyter Notebook or similar interactive environment. ```python grid ``` -------------------------------- ### Configure Grid Layout and Column Sizing Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/ui-tests-ipw8/tests/notebooks/datagrid_nested_hierarchies_update.ipynb Adjusts the visual properties of the grid, including enabling auto-fit for columns and setting base column sizes to optimize data display. ```python nested_grid.auto_fit_columns = True nested_grid.base_column_size = 79 ``` -------------------------------- ### Initialize ipydatagrid with pandas DataFrame Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/ui-tests-ipw8/tests/notebooks/date.ipynb This snippet creates a pandas DataFrame with datetime columns and renders it as an interactive ipydatagrid. It sets a base column size to ensure proper visibility of the data. ```python import datetime import pandas as pd import ipydatagrid df = pd.DataFrame( { 'A': [datetime.datetime(2024, 8, 5) - datetime.timedelta(days=1), datetime.datetime(2024, 11, 5)], 'B': [datetime.datetime(2024, 10, 5) - datetime.timedelta(days=1), datetime.datetime(2024, 10, 5)], }, ) dg = ipydatagrid.DataGrid(df, base_column_size=250) dg ``` -------------------------------- ### Programmatically Select Grid Regions Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/examples/Selections.ipynb Shows how to select rectangular regions or individual cells using row and column indices. Includes options for clearing existing selections. ```python datagrid.select(row1=1, column1=1, row2=2, column2=2, clear_mode="all") datagrid.select(1, 1, 2, 2) datagrid.select(2, 2, 3, 3) datagrid.select(4, 1) datagrid.select(6, 1, clear_mode="current") ``` -------------------------------- ### Selection and Auto-fit API Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/ui-tests-ipw7/tests/notebooks/datagrid_base_update.ipynb Methods to manage user selections and automatic column sizing behavior. ```APIDOC ## SET grid.selection_mode ### Description Defines how the grid handles user selection (e.g., 'row', 'column'). ### Request Example ```python grid.selection_mode = 'row' grid.select(5, 4) ``` ``` ```APIDOC ## SET grid.auto_fit_columns ### Description Enables or disables automatic column width calculation based on content. ### Parameters - **auto_fit** (boolean) - Required - Enable or disable auto-fit. - **params** (dict) - Optional - Configuration for area, padding, and column count. ### Request Example ```python grid.auto_fit_columns = True grid.auto_fit_params = {'area': 'body', 'padding': 80, 'numCols': 3} ``` ``` -------------------------------- ### HyperlinkRenderer Usage Source: https://github.com/jupyter-widgets/ipydatagrid/blob/main/examples/HyperlinkRenderer.ipynb Demonstrates how to create and use the HyperlinkRenderer with a pandas DataFrame in ipydatagrid. ```APIDOC ## HyperlinkRenderer ### Description A renderer which allows for rendering text-based clickable links as cells in your DataGrid. It takes two parameters: `url` and `urlName`, both Vega Expression functions. Links can only be opened by clicking whilst holding the `Ctrl` or `Command` key pressed. The `HyperlinkRenderer` can be styled using all properties supported by the `TextRenderer`. ### Parameters #### Renderer Properties - **url** (VegaExpr) - Required - A Vega Expression function which points to a full URL (with the http(s) prefix). - **urlName** (VegaExpr) - Required - A Vega Expression function which points to a friendly URL display name. ### Request Example ```python import pandas as pd from ipydatagrid import VegaExpr, DataGrid, HyperlinkRenderer df = pd.DataFrame( data={ "Name": ["NumFocus"], "Link": [["https://numfocus.org/", "Better tools to build a better worlds."]], } ) link_renderer = HyperlinkRenderer( url=VegaExpr("cell.value[0]"), url_name=VegaExpr("cell.value[1]"), background_color="moccasin", text_color="blue", font="bold 14px Arial, sans-serif", ) grid = DataGrid( df, layout={"height": "120px"}, base_column_size=200, renderers={"Link": link_renderer}, ) grid ``` ### Response #### Success Response (200) N/A - This is a client-side rendering component. #### Response Example N/A ```