Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@ashm-dev
Copy link
Contributor

@ashm-dev ashm-dev commented Feb 7, 2025

Describe your changes

Added

  • Support for string file paths as page inputs
  • Support for functions as page inputs
  • New utility function convert_to_streamlit_page for converting various input types to StreamlitPage
  • Extended documentation with new usage examples

Changed

  • Updated st.navigation interface to accept mixed input types
  • Improved typing for navigation function parameters
  • Extended unit tests to cover new use cases

Documentation

  • Added detailed examples for various input types
  • Updated parameter descriptions
  • Added examples for working with stateful widgets

GitHub Issue Link (if applicable)

Closes #10069

Testing Plan

The necessary tests have already been added


Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@ashm-dev ashm-dev force-pushed the feature-10069 branch 3 times, most recently from 610b6f0 to 450e343 Compare February 8, 2025 12:13
@kmcgrady kmcgrady self-requested a review February 10, 2025 19:04
@kmcgrady kmcgrady self-assigned this Feb 10, 2025
Copy link
Collaborator

@kmcgrady kmcgrady left a comment

Choose a reason for hiding this comment

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

Hey @ashm-dev Thanks for the PR. Let me double check with @jrieke on whether we want to support direct strings here. I see how this can be simpler, but I also see this as obfuscating the API at the possibilities.

EDIT: Ah I see @jrieke wrote the issue, so I bet he agrees. I'll double check and give this a review.

@jrieke
Copy link
Collaborator

jrieke commented Feb 11, 2025

This is awesome, thanks so much @ashm-dev! I actually started a similar PR a while ago (#10074) but didn't get around to finish it up, so happy to let you take it across the finish line ;) Only had a brief look at the PR but my 2 cts:

  1. Let's to also support pathlib.Path objects in addition to strings pointing to paths. We do that everywhere else in the API too and should be very easy to add.
  2. For the docstring changes, please also get approval from @sfc-gh-dmatthews. Might also make sense to get them into a separate PR, so we can merge this one faster but will let y'all figure this out! Feel free to also take a look at my PR for inspiration on how to describe the possible formats for defining pages.

@kmcgrady when this is merged, you can also close my PR.

@ashm-dev
Copy link
Contributor Author

Got it, thank you for such feedback!

Then I just add the ability to work with pathlib.Path, I add tests for this and add docstring documentation)

@ashm-dev ashm-dev force-pushed the feature-10069 branch 2 times, most recently from 8138940 to 3eadc2a Compare February 11, 2025 21:12
@ashm-dev ashm-dev requested a review from kmcgrady February 11, 2025 21:12
@sfc-gh-dmatthews
Copy link
Collaborator

sfc-gh-dmatthews commented Feb 11, 2025

I can change the docstrings in a followup PR since I'll need to change a bit.

Although I'm already planning on implementing support for Notes and Raises, we don't use those yet so I'll reformat that information. (Otherwise, it can have unintended consequences for the docstring parser or docs site.) I'm planning on comprehensively documenting raised exceptions, but since no other public command has this yet, I'm inclined to leave it out until I take a pass at getting some basic coverage across the board for consistency. The examples section needs to keep its embedded apps and header labels, so I'll need to rework the examples and make sure the apps are consistent. Since that will take me a little time, I'll just do a followup to make it easy. 😃

@ashm-dev
Copy link
Contributor Author

@sfc-gh-dmatthews Ok got it, should I fix it in the current version, or is this PR already accepted, and you will update it yourself in the next one?

@sfc-gh-dmatthews
Copy link
Collaborator

@ashm-dev I can update it in the next PR.

@ashm-dev
Copy link
Contributor Author

When will my PR be merged?

@kmcgrady
Copy link
Collaborator

Hey @ashm-dev I will review this today and hopefully it will be close. I can expect it to be merged this week. Our cutoff is set for Wednesday Feb 26th in the evening (Pacific Time), so we have plenty of time :-)

Copy link
Collaborator

@kmcgrady kmcgrady left a comment

Choose a reason for hiding this comment

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

Everything looks great. Just some small comments (and making sure the checks all pass), and we can get this merged.


if callable(page_input):
# Convert function to StreamlitPage
return Page(page_input)
Copy link
Collaborator

Choose a reason for hiding this comment

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

For these, we want to use StreamlitPage, not Page. Page is annotated to assume it's an st call where StreamlitPage is the underlying function.


raise StreamlitAPIException(
f"Invalid page type: {type(page_input)}. Must be either a string path, "
"a callable function, or a StreamlitPage object."
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably should call this st.Page object since this is what users would be seeing.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I call the object by its name in docs. st.Page isn't a class; it's a command to create an instance of a class. So st.Page is a command you call; StreamlitPage is the object you get from it.

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 followed the same logic, but once they said update, I redid it)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'll defer to Debbie here since she's our docs expert. If StreamlitPage makes the most sense, we can leave it as is (and sorry for the thrash)

@ashm-dev ashm-dev requested a review from kmcgrady February 18, 2025 11:14
@kmcgrady kmcgrady added security-assessment-completed Security assessment has been completed for PR change:feature PR contains new feature or enhancement implementation labels Feb 18, 2025
@kmcgrady kmcgrady added the impact:users PR changes affect end users label Feb 18, 2025
@kmcgrady
Copy link
Collaborator

Looking at the tests failing tests. I think you need to:

  1. Run precommit. This would be running pre-commit run --all-files in the directory, which I think should work. If not, you may need to just read the suggested changes.
  2. Looks like Python tests just need that pre-commit run to format the python files and it will continue (assuming the tests pass)

@ashm-dev
Copy link
Contributor Author

@kmcgrady Yes, there was a minor error in types and formatting, I fixed it, now I hope everything goes as it should)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like this was created by mistake and committed. Should remove that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

Copy link
Collaborator

@kmcgrady kmcgrady left a comment

Choose a reason for hiding this comment

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

Homestretch. Looks like there were some files erroneously added. Can you remove them? I think the only thing is to remove references to Page in favor of StreamlitPage

@kmcgrady kmcgrady merged commit 6fc6d44 into streamlit:develop Feb 20, 2025
31 checks passed
@kmcgrady
Copy link
Collaborator

Thanks @ashm-dev !

@ashm-dev ashm-dev deleted the feature-10069 branch February 20, 2025 15:56
@jrieke
Copy link
Collaborator

jrieke commented Feb 20, 2025

Awesome, thanks for adding this @ashm-dev! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pass file path or function directly to st.navigation, without using st.Page

4 participants