Skip to content

Sparklines ? #118

@dcowden

Description

@dcowden

Hi, thank you for the excellent python module!

I'm trying to use AGGrid's relatively new ( October 2021) Sparklines feature:

https://ag-grid.com/javascript-data-grid/sparklines-overview/

I am using these libs, which at the time of this writing are the latest:

streamlit             1.11.1
streamlit-aggrid      0.2.3.post2

I think this simple example should yeild a grid with sparklines in the history column:

import pandas as pd
import streamlit as st
from st_aggrid import AgGrid,GridUpdateMode, GridOptionsBuilder,DataReturnMode,JsCode

def compute_simple_data():
    return pd.DataFrame({
        'name': [ 'a','b'] ,
        'history' : [ [1,2,0,0,1,0,2],[1,0,0,0,2,2,2,2,] ]})

simple_data = compute_simple_data()


gb = GridOptionsBuilder.from_dataframe(simple_data)
gb.configure_side_bar()
gb.configure_column('history', cellRenderer='agSparklineCellRenderer') 
gridOptions = gb.build()

print(gridOptions)
print(simple_data.info())
g = AgGrid(
    simple_data,
    gridOptions=gridOptions,
    allow_unsafe_jscode=True,
    enable_enterprise_modules=True
)

But it renders an empty column, like this:

image

I have a feeling that this has to do with the format of the data. pandas reports the column as an object:

Data columns (total 2 columns):
 #   Column   Non-Null Count  Dtype 
---  ------   --------------  ----- 
 0   name     2 non-null      object
 1   history  2 non-null      object
dtypes: object(2)
memory usage: 160.0+ bytes

And Aggrid sparkline expects a numeric javascript array

I know that an attempt is being made to apply the agSparkLineCellRenderer because if we comment out the configure_column call, we get the expected result:
image

Using browser console, there are no javascript errors reported (other than the AGgrid license warning).

I also tried applying type='number' and type='numeric' in the column properties, with the same blank column behavior.

I suspect i'm missing a pretty simple data conversion issue here, or alternately it could be that the aggride version being used is older.

Help would be appreciated!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions