Get pygwalker html render to streamlit. In Streamlit, pygwalker calculates a somewhat inaccurate gid based on the dataset to distinguish between datasets and uses it as the key for the Streamlit component to avoid redundant rendering. In some use case, If user frequ
(
self,
dataset: Union[DataFrame, Connector],
gid: Union[int, str] = None,
*,
field_specs: Optional[List[FieldSpec]] = None,
theme_key: IThemeKey = 'g2',
appearance: IAppearance = 'media',
spec: str = "",
spec_io_mode: ISpecIOMode = "r",
kernel_computation: Optional[bool] = None,
use_kernel_calc: Optional[bool] = True,
show_cloud_tool: Optional[bool] = None,
kanaries_api_key: str = "",
default_tab: Literal["data", "vis"] = "vis",
**kwargs
)
| 50 | class StreamlitRenderer: |
| 51 | """Streamlit Renderer""" |
| 52 | def __init__( |
| 53 | self, |
| 54 | dataset: Union[DataFrame, Connector], |
| 55 | gid: Union[int, str] = None, |
| 56 | *, |
| 57 | field_specs: Optional[List[FieldSpec]] = None, |
| 58 | theme_key: IThemeKey = 'g2', |
| 59 | appearance: IAppearance = 'media', |
| 60 | spec: str = "", |
| 61 | spec_io_mode: ISpecIOMode = "r", |
| 62 | kernel_computation: Optional[bool] = None, |
| 63 | use_kernel_calc: Optional[bool] = True, |
| 64 | show_cloud_tool: Optional[bool] = None, |
| 65 | kanaries_api_key: str = "", |
| 66 | default_tab: Literal["data", "vis"] = "vis", |
| 67 | **kwargs |
| 68 | ): |
| 69 | """Get pygwalker html render to streamlit. |
| 70 | In Streamlit, pygwalker calculates a somewhat inaccurate gid based on the dataset to |
| 71 | distinguish between datasets and uses it as the key for the Streamlit component to |
| 72 | avoid redundant rendering. |
| 73 | |
| 74 | In some use case, If user frequently use the same StreamlitRenderer to receive different dataframes, |
| 75 | and the differences between these dataframes are so small that pygwalker's gid calculation logic cannot distinguish between different datasets, |
| 76 | user should customize method to generate a gid to differentiate between datasets. |
| 77 | |
| 78 | Args: |
| 79 | - dataset (pl.DataFrame | pd.DataFrame | Connector, optional): dataframe. |
| 80 | - gid (Union[int, str], optional): GraphicWalker container div's id ('gwalker-{gid}') |
| 81 | |
| 82 | Kargs: |
| 83 | - field_specs (List[FieldSpec], optional): Specifications of some fields. They'll been automatically inferred from `df` if some fields are not specified. |
| 84 | - theme_key ('vega' | 'g2'): theme type. |
| 85 | - appearance (Literal['media' | 'light' | 'dark']): 'media': auto detect OS theme. |
| 86 | - spec (str): chart config data. config id, json, remote file url |
| 87 | - spec_io_mode (ISpecIOMode): spec io mode, Default to "r", "r" for read, "rw" for read and write. |
| 88 | - kernel_computation(bool): Whether to use kernel compute for datas, Default to True. |
| 89 | - use_kernel_calc(bool): Deprecated, use kernel_computation instead. |
| 90 | - kanaries_api_key (str): kanaries api key, Default to "". |
| 91 | - default_tab (Literal["data", "vis"]): default tab to show. Default to "vis" |
| 92 | """ |
| 93 | check_expired_params(kwargs) |
| 94 | |
| 95 | init_streamlit_comm() |
| 96 | |
| 97 | self.walker = PygWalker( |
| 98 | gid=gid if gid is not None else get_dataset_hash(dataset), |
| 99 | dataset=dataset, |
| 100 | field_specs=field_specs if field_specs is not None else [], |
| 101 | spec=spec, |
| 102 | source_invoke_code="", |
| 103 | theme_key=theme_key, |
| 104 | appearance=appearance, |
| 105 | show_cloud_tool=show_cloud_tool, |
| 106 | use_preview=False, |
| 107 | kernel_computation=isinstance(dataset, Connector) or fallback_value(kernel_computation, use_kernel_calc), |
| 108 | use_save_tool="w" in spec_io_mode, |
| 109 | is_export_dataframe=False, |
nothing calls this directly
no test coverage detected