-
Notifications
You must be signed in to change notification settings - Fork 737
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
624 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,7 @@ dependencies: | |
- python>=3.5 | ||
- pip | ||
- polars | ||
- bottle | ||
- pywebview | ||
- pip: | ||
- pygwalker>=0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from pygwalker.adapter.utils import can_open_window, is_notebook | ||
from pygwalker.api import repl, webview, jupyter | ||
from typing import Optional, Union | ||
from pygwalker._typing import DataFrame, IAppearance, IThemeKey | ||
from pygwalker.data_parsers.database_parser import Connector | ||
|
||
def render( | ||
dataset: Union[DataFrame, Connector, str], | ||
spec: str, | ||
*, | ||
theme_key: IThemeKey = 'g2', | ||
appearance: IAppearance = 'media', | ||
kernel_computation: Optional[bool] = None, | ||
kanaries_api_key: str = "", | ||
**kwargs | ||
): | ||
""" | ||
Args: | ||
- dataset (pl.DataFrame | pd.DataFrame | Connector, optional): dataframe. | ||
- spec (str): chart config data. config id, json, remote file url | ||
Kargs: | ||
- theme_key ('vega' | 'g2'): theme type. | ||
- appearance (Literal['media' | 'light' | 'dark']): 'media': auto detect OS theme. | ||
- kernel_computation(bool): Whether to use kernel compute for datas, Default to None. | ||
- kanaries_api_key (str): kanaries api key, Default to "". | ||
""" | ||
|
||
if is_notebook(): | ||
return jupyter.render( | ||
dataset, | ||
spec, | ||
theme_key=theme_key, | ||
appearance=appearance, | ||
kernel_computation=kernel_computation, | ||
kanaries_api_key=kanaries_api_key, | ||
**kwargs | ||
) | ||
elif can_open_window(): | ||
return webview.render( | ||
dataset, | ||
spec, | ||
theme_key=theme_key, | ||
appearance=appearance, | ||
kernel_computation=kernel_computation, | ||
kanaries_api_key=kanaries_api_key, | ||
**kwargs | ||
) | ||
else: | ||
return repl.render( | ||
dataset, | ||
spec, | ||
theme_key=theme_key, | ||
appearance=appearance, | ||
kernel_computation=kernel_computation, | ||
kanaries_api_key=kanaries_api_key, | ||
**kwargs | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from pygwalker.adapter.utils import can_open_window, is_notebook | ||
from pygwalker.api import repl, webview, jupyter | ||
from typing import Optional, Union | ||
from pygwalker._typing import DataFrame, IAppearance, IThemeKey | ||
from pygwalker.data_parsers.database_parser import Connector | ||
|
||
def table( | ||
dataset: Union[DataFrame, Connector, str], | ||
*, | ||
theme_key: IThemeKey = 'g2', | ||
appearance: IAppearance = 'media', | ||
kernel_computation: Optional[bool] = None, | ||
kanaries_api_key: str = "", | ||
**kwargs | ||
): | ||
""" | ||
Args: | ||
- dataset (pl.DataFrame | pd.DataFrame | Connector, optional): dataframe. | ||
Kargs: | ||
- theme_key ('vega' | 'g2'): theme type. | ||
- appearance (Literal['media' | 'light' | 'dark']): 'media': auto detect OS theme. | ||
- kernel_computation(bool): Whether to use kernel compute for datas, Default to None. | ||
- kanaries_api_key (str): kanaries api key, Default to "". | ||
""" | ||
|
||
if is_notebook(): | ||
return jupyter.table( | ||
dataset, | ||
theme_key=theme_key, | ||
appearance=appearance, | ||
kernel_computation=kernel_computation, | ||
kanaries_api_key=kanaries_api_key, | ||
**kwargs | ||
) | ||
elif can_open_window(): | ||
return webview.table( | ||
dataset, | ||
theme_key=theme_key, | ||
appearance=appearance, | ||
kernel_computation=kernel_computation, | ||
kanaries_api_key=kanaries_api_key, | ||
**kwargs | ||
) | ||
else: | ||
return repl.table( | ||
dataset, | ||
theme_key=theme_key, | ||
appearance=appearance, | ||
kernel_computation=kernel_computation, | ||
kanaries_api_key=kanaries_api_key, | ||
**kwargs | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
def is_notebook() -> bool: | ||
try: | ||
shell = get_ipython().__class__.__name__ | ||
if shell == 'ZMQInteractiveShell': | ||
return True # Jupyter notebook or qtconsole | ||
elif shell == 'TerminalInteractiveShell': | ||
return False # Terminal running IPython | ||
else: | ||
return False # Other type (?) | ||
except NameError: | ||
return False # Probably standard Python interpreter | ||
|
||
def can_open_window() -> bool: | ||
import os | ||
import platform | ||
|
||
# Check if running in SSH session | ||
if 'SSH_CONNECTION' in os.environ: | ||
return False | ||
|
||
system = platform.system() | ||
|
||
if system == 'Darwin': # macOS | ||
# macOS can typically always open windows unless in remote session | ||
return True | ||
elif system == 'Linux': | ||
# Check for X11 or Wayland display | ||
return bool(os.environ.get('DISPLAY') or os.environ.get('WAYLAND_DISPLAY')) | ||
elif system == 'Windows': | ||
# Windows can typically always open windows unless in remote session | ||
return True | ||
else: | ||
return False # Unknown OS, assume no GUI capability |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
from pygwalker.adapter.utils import is_notebook, can_open_window | ||
from pygwalker.api import repl, webview, jupyter | ||
from typing import List, Optional, Union | ||
from pygwalker._typing import DataFrame, IAppearance, IThemeKey | ||
from pygwalker.data_parsers.database_parser import Connector | ||
from typing_extensions import Literal | ||
from pygwalker.data_parsers.base import FieldSpec | ||
|
||
|
||
def walk( | ||
dataset: Union[DataFrame, Connector, str], | ||
gid: Union[int, str] = None, | ||
*, | ||
env: Literal['Jupyter', 'JupyterWidget'] = 'JupyterWidget', | ||
field_specs: Optional[List[FieldSpec]] = None, | ||
theme_key: IThemeKey = 'g2', | ||
appearance: IAppearance = 'media', | ||
spec: str = "", | ||
use_kernel_calc: Optional[bool] = None, | ||
kernel_computation: Optional[bool] = None, | ||
cloud_computation: bool = False, | ||
show_cloud_tool: bool = True, | ||
kanaries_api_key: str = "", | ||
default_tab: Literal["data", "vis"] = "vis", | ||
**kwargs | ||
): | ||
"""Walk through pandas.DataFrame df with Graphic Walker | ||
Args: | ||
- dataset (pl.DataFrame | pd.DataFrame | Connector, optional): dataframe. | ||
- gid (Union[int, str], optional): GraphicWalker container div's id ('gwalker-{gid}') | ||
Kargs: | ||
- env: (Literal['Jupyter' | 'JupyterWidget'], optional): The enviroment using pygwalker. Default as 'JupyterWidget' | ||
- field_specs (List[FieldSpec], optional): Specifications of some fields. They'll been automatically inferred from `df` if some fields are not specified. | ||
- theme_key ('vega' | 'g2' | 'streamlit'): theme type. | ||
- appearance (Literal['media' | 'light' | 'dark']): 'media': auto detect OS theme. | ||
- spec (str): chart config data. config id, json, remote file url | ||
- use_kernel_calc(bool): Whether to use kernel compute for datas, Default to None, automatically determine whether to use kernel calculation. | ||
- kanaries_api_key (str): kanaries api key, Default to "". | ||
- default_tab (Literal["data", "vis"]): default tab to show. Default to "vis" | ||
- cloud_computation(bool): Whether to use cloud compute for datas, it upload your data to kanaries cloud. Default to False. | ||
""" | ||
if is_notebook(): | ||
return jupyter.walk( | ||
dataset, | ||
gid, | ||
env=env, | ||
field_specs=field_specs, | ||
theme_key=theme_key, | ||
appearance=appearance, | ||
spec=spec, | ||
use_kernel_calc=use_kernel_calc, | ||
kernel_computation=kernel_computation, | ||
cloud_computation=cloud_computation, | ||
show_cloud_tool=show_cloud_tool, | ||
kanaries_api_key=kanaries_api_key, | ||
default_tab=default_tab, | ||
**kwargs | ||
) | ||
elif can_open_window(): | ||
return webview.walk( | ||
dataset, | ||
gid, | ||
env=env, | ||
field_specs=field_specs, | ||
theme_key=theme_key, | ||
appearance=appearance, | ||
spec=spec, | ||
use_kernel_calc=use_kernel_calc, | ||
kernel_computation=kernel_computation, | ||
cloud_computation=cloud_computation, | ||
show_cloud_tool=show_cloud_tool, | ||
kanaries_api_key=kanaries_api_key, | ||
default_tab=default_tab, | ||
**kwargs | ||
) | ||
else: | ||
return repl.walk( | ||
dataset, | ||
gid, | ||
env=env, | ||
field_specs=field_specs, | ||
theme_key=theme_key, | ||
appearance=appearance, | ||
spec=spec, | ||
use_kernel_calc=use_kernel_calc, | ||
kernel_computation=kernel_computation, | ||
cloud_computation=cloud_computation, | ||
show_cloud_tool=show_cloud_tool, | ||
kanaries_api_key=kanaries_api_key, | ||
default_tab=default_tab, | ||
**kwargs | ||
) |
Oops, something went wrong.