Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add pygwalker web api tips in streamlit #585

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pygwalker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pygwalker.services.global_var import GlobalVarManager
from pygwalker.services.kaggle import show_tips_user_kaggle as __show_tips_user_kaggle

__version__ = "0.4.9"
__version__ = "0.4.9.1"
__hash__ = __rand_str()

from pygwalker.api.jupyter import walk, render, table
Expand Down
17 changes: 13 additions & 4 deletions pygwalker/communications/streamlit_comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import streamlit as st

from pygwalker.utils.encode import DataFrameEncoder
from pygwalker.errors import StreamlitPygwalkerApiError
from .base import BaseCommunication

streamlit_comm_map = {}
Expand Down Expand Up @@ -46,11 +47,19 @@ def post(self, gid: str):
def hack_streamlit_server():
tornado_obj = None
for obj in gc.get_objects():
if isinstance(obj, Application):
tornado_obj = obj
break
try:
if isinstance(obj, Application):
for rule in obj.wildcard_router.rules:
if "streamlit" in str(rule.target):
tornado_obj = obj
break
except Exception:
pass

tornado_obj.add_handlers(".*", [(PYGWALKER_API_PATH, PygwalkerHandler)])
if tornado_obj:
tornado_obj.add_handlers(".*", [(PYGWALKER_API_PATH, PygwalkerHandler)])
else:
raise StreamlitPygwalkerApiError()


class StreamlitCommunication(BaseCommunication):
Expand Down
9 changes: 9 additions & 0 deletions pygwalker/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,12 @@ def __init__(self) -> None:
"The query returned too many data entries, making it difficult for the frontend to render. Please adjust your chart configuration and try again.",
code=ErrorCode.UNKNOWN_ERROR
)


class StreamlitPygwalkerApiError(BaseError):
"""Raised when the config is invalid."""
def __init__(self) -> None:
super().__init__(
"Adding pygwalker web api to streamlit failed. If possible, please report this case to the pygwalker team. Thanks!",
code=ErrorCode.UNKNOWN_ERROR
)
Loading