Skip to content

refactor: deprecate kwargs in st.plotly_chart and add config dict instead#12291

Merged
lukasmasuch merged 8 commits intostreamlit:developfrom
zyfy29:plotly-chart-deprecate-kwargs
Aug 29, 2025
Merged

refactor: deprecate kwargs in st.plotly_chart and add config dict instead#12291
lukasmasuch merged 8 commits intostreamlit:developfrom
zyfy29:plotly-chart-deprecate-kwargs

Conversation

@zyfy29
Copy link
Copy Markdown
Contributor

@zyfy29 zyfy29 commented Aug 22, 2025

Describe your changes

mark the **kwargs of st.plotly_chart as deprecated, and add a new config argument to directly pass to plot()

GitHub Issue Link (if applicable)

Testing Plan

This is a refactor and doesn't break the existing e2e tests for st.plotly_chart, so no new tests are needed.


Contribution License Agreement

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

Copilot AI review requested due to automatic review settings August 22, 2025 09:58
@snyk-io
Copy link
Copy Markdown
Contributor

snyk-io bot commented Aug 22, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the st.plotly_chart function to deprecate the use of **kwargs and introduces a new config parameter for passing configuration options directly to Plotly's plot() function. This change improves the API's clarity and follows best practices by making the configuration parameter explicit rather than relying on generic keyword arguments.

Key changes:

  • Added a new config parameter of type dict | None to the function signature
  • Added deprecation warning for **kwargs usage
  • Updated parameter documentation to reflect the new config parameter and deprecation

Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
@lukasmasuch lukasmasuch added change:breaking PR contains breaking change that affects backwards compatibility change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users status:needs-product-approval PR requires product approval before merging labels Aug 22, 2025
"box",
"lasso",
),
config: dict | None = None,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The config parameter requires a more specific type annotation. Replace dict | None with dict[str, Any] | None to specify the dictionary's key-value types. The Python Guide mandates adding proper typing annotations to every new function parameter, and generic dict typing does not meet this requirement.

Suggested change
config: dict | None = None,
config: dict[str, Any] | None = None,

Spotted by Diamond (based on custom rule: Python Guide)

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

Comment on lines +555 to +560
if config is None:
config = dict(kwargs.get("config", {}))
# Copy over some kwargs to config dict. Plotly does the same in plot().
# TODO: Remove this once we remove the kwargs support.
config.setdefault("showLink", kwargs.get("show_link", False))
config.setdefault("linkText", kwargs.get("link_text", False))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Issue: When a config parameter is provided, deprecated kwargs like show_link and link_text are silently ignored rather than being merged into the config.

This creates inconsistent behavior where the same kwargs work when config=None but have no effect when a config is provided. For proper backward compatibility during the deprecation period, the kwargs should still be processed and merged into any user-provided config dict.

Consider modifying the code to merge the kwargs into the config regardless of whether config was provided by the user:

config = dict(config or {})
# Always merge kwargs into config for backward compatibility
config.setdefault("showLink", kwargs.get("show_link", False))
config.setdefault("linkText", kwargs.get("link_text", False))
Suggested change
if config is None:
config = dict(kwargs.get("config", {}))
# Copy over some kwargs to config dict. Plotly does the same in plot().
# TODO: Remove this once we remove the kwargs support.
config.setdefault("showLink", kwargs.get("show_link", False))
config.setdefault("linkText", kwargs.get("link_text", False))
config = dict(config or {})
# Copy over some kwargs to config dict. Plotly does the same in plot().
# TODO: Remove this once we remove the kwargs support.
config.setdefault("showLink", kwargs.get("show_link", False))
config.setdefault("linkText", kwargs.get("link_text", False))

Spotted by Diamond

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

@sfc-gh-jrieke
Copy link
Copy Markdown
Contributor

Hey @zyfy29, thanks for the contribution! Looks good from product side overall, I just left a few small comments above and we should also make sure this is raising a deprecation warning if a kwarg is passed (which I think it doesn't currently?). Will let our engineers give you more feedback on the code :)

@sfc-gh-jrieke sfc-gh-jrieke added status:product-approved Community PR is approved by product team and removed status:needs-product-approval PR requires product approval before merging labels Aug 22, 2025
@sfc-gh-lwilby
Copy link
Copy Markdown
Collaborator

Hi @zyfy29 ,

Thanks for submitting this PR!

I left one inline comment, but also,

This is a refactor and doesn't break the existing e2e tests for st.plotly_chart, so no new tests are needed.

I think some test coverage is needed to handle the new case of config being provided.

Also, if @jrieke wants us to provide users with a warning if they try to pass kwargs other than the ones mentioned in the docstring, we will need to add some logic to validate the contents of the kwargs dict and then provide the deprecation warning (note we have a util function for this show_deprecation_warning) and it would be good to add test coverage for this as well.

I have run the CI, and it looks like there are some failures that need to be addressed.

Thanks again for your submission! Let me know if you need any more details on getting this PR merge-ready.

Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
@zyfy29
Copy link
Copy Markdown
Contributor Author

zyfy29 commented Aug 23, 2025

Thank you for the suggestions! I've updated my pr and added a unit test case. I noticed that some e2e test cases using the config dict argument already exist. If a new e2e test case is also needed please tell me and I'll try to do that.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@sfc-gh-bnisco sfc-gh-bnisco requested a review from Copilot August 25, 2025 16:26
@zyfy29
Copy link
Copy Markdown
Contributor Author

zyfy29 commented Aug 26, 2025

Sorry, I submitted 6a1c15c from copilot but forgot the unit tests. Now It should be OK.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
Collaborator

@sfc-gh-lwilby sfc-gh-lwilby left a comment

Choose a reason for hiding this comment

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

Thanks @zyfy29 this test coverage looks good to me now.

Comment on lines -545 to -548
config = dict(kwargs.get("config", {}))
# Copy over some kwargs to config dict. Plotly does the same in plot().
config.setdefault("showLink", kwargs.get("show_link", False))
config.setdefault("linkText", kwargs.get("link_text", False))
Copy link
Copy Markdown
Collaborator

@lukasmasuch lukasmasuch Aug 29, 2025

Choose a reason for hiding this comment

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

Just double-checking: we already want to fully remove support for kwargs in this PR? The alternative option would be to show a deprecation warning but keep supporting kwargs in addition to config for some time? cc @sfc-gh-jrieke

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Oh no, definitely show a deprecation warning for now but keep kwargs support. I think we can already get rid of copying showLink and linkText to config, since those params don't seem to be used.

config.setdefault("showLink", kwargs.get("show_link", False))
config.setdefault("linkText", kwargs.get("link_text", False))

config = config or {}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we need to do something like: config = config or dict(kwargs.get("config", {})) here to still support kwargs for now. See comment from @sfc-gh-jrieke above.

Copy link
Copy Markdown
Collaborator

@lukasmasuch lukasmasuch Aug 29, 2025

Choose a reason for hiding this comment

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

I took another look at the adoption numbers and I think it's actually fine as is: config is the most used kwarg, which we will support here via the explicit config parameter. Besides that, usage of other parameters is almost non-existent and hasn't been supported anyways (other than showLink and linkText)

@lukasmasuch lukasmasuch merged commit a03c8d4 into streamlit:develop Aug 29, 2025
35 of 37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:breaking PR contains breaking change that affects backwards compatibility change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users status:product-approved Community PR is approved by product team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deprecate **kwargs in st.plotly_chart and add config instead

6 participants