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

refactor for toml no null #108

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "st-pages"
version = "1.0.1"
version = "1.0.2"
license = "MIT"
description = "An experimental version of Streamlit Multi-Page Apps"
authors = ["Zachary Blackwood <[email protected]>"]
Expand Down
14 changes: 8 additions & 6 deletions src/st_pages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def _get_nav_from_toml(

for page in pages:
if page.is_section:
if page.icon is not None:
if hasattr(page, "icon") and page.icon != "":
current_section = f"{translate_icon(page.icon)} {page.name}"
else:
current_section = cast(str, page.name)
Expand All @@ -89,7 +89,7 @@ def _get_nav_from_toml(
st.Page(
page.path,
title=page.name,
icon=translate_icon(page.icon),
icon=translate_icon(page.icon if hasattr(page, "icon") else None),
url_path=page.url_path,
)
)
Expand All @@ -104,7 +104,7 @@ def _get_nav_from_toml(
st.Page(
page.path,
title=page.name,
icon=translate_icon(page.icon),
icon=translate_icon(page.icon if hasattr(page, "icon") else None),
url_path=page.url_path,
)
)
Expand Down Expand Up @@ -132,12 +132,12 @@ def _add_page_title(page: StreamlitPage):
Adds the icon and page name to the page as an st.title.
"""
page_title = page.title
page_icon = translate_icon(page.icon)
page_icon = translate_icon(page.icon if hasattr(page, "icon") else None)

if page_icon and "/" in page_icon:
page_icon = None

st.title(f"{page_icon} {page_title}" if page_icon else page_title)
st.title(f"{page_icon} {page_title}" if hasattr(page, "icon") else page_title)


add_page_title = gather_metrics("st_pages.add_page_title", _add_page_title)
Expand Down Expand Up @@ -199,7 +199,9 @@ def _get_pages_from_config(path: str = ".streamlit/pages.toml") -> list[Page] |
for page in raw_pages:
if page.get("is_section"):
page["path"] = ""
pages.append(Section(page["name"], page["icon"])) # type: ignore
pages.append(
Section(page["name"], page["icon"] if hasattr(page, "icon") else None)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be the only required change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah..got it..cool..I will make the changes in some time!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done now ..thanks for the help!

Copy link
Contributor Author

@Sairam90 Sairam90 Sep 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are two fixes left:

  1. here - It needs to be if page.icon: instead as icon defaults to '' (empty string) here

  2. here
    - It needs to be page.get("icon") - so that the section icons get rendered

Let me know your thoughts - I can make the changes later today

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. The icon should not default to '', but to None -- are you sure it's defaulting to ''?

  2. Yeah, page.get("icon") should work well there

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, cause I see the leading space issue in the section name alone in this case,though am not sure why it defaults to ‘’ instead of None

) # type: ignore
else:
pages.append(Page(**page)) # type: ignore
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about handling "icon" here the same way you've handled it in the "if section" block above? That seems like it would nicely handle a lot of the other checks, and could simply default to null.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, I will work on it tom and get back !

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made the changes to set icon to None when initializing here but I think the string null check has to be done separately when setting the page title and section names.

Let me know if that looks good!


Expand Down
Loading