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

Include tooltip() and popover() in express #949

Merged
merged 2 commits into from
Jan 3, 2024
Merged

Include tooltip() and popover() in express #949

merged 2 commits into from
Jan 3, 2024

Conversation

cpsievert
Copy link
Collaborator

Closes #946

@wch
Copy link
Collaborator

wch commented Jan 2, 2024

I wasn't sure what API we want for these functions. With this PR, these functions need to be used in the non-context-manager way:

from shiny.express import ui

ui.tooltip(
    ui.input_action_button("btn", "A button"),
    "A message",
    id="btn_tooltip",
)

This is quite different from the other context manager stuff in Express. Also, if the user wants to have nested content for either the trigger or tooltip/popover, they will need to have a separate import of shiny.ui and use those functions.

Here are a few possible ways of doing this with context managers. Note that in all cases, the kwargs (like id) needs to be passed in immediately.

# (1) Passing values straight through
with ui.tooltip(id="btn_tooltip"):
    ui.input_action_button("btn", "A button")
    "A message"
    

# (2) Taking the `trigger` argument:
with ui.tooltip(ui.input_action_button("btn", "A button"), id="btn_tooltip"):
    "A message"


# (3) Taking the *args:
with ui.tooltip("A message", id="btn_tooltip"):
    ui.input_action_button("btn", "A button")

I have to say that I don't really love any of these, but I think (1) is the least weird.

With (1), it's weird that the kwargs have to go to the into the function call immediately, but then the unnamed args come later, after the trigger.

With (2), it feels strange to me that the trigger are passed in alongside the kwargs, and then the unnamed args come later. The reason it feels weird is because the kwargs are conceptually more closely associated with the unnamed args, than with the trigger. It is also limiting if you want a large trigger.

(3) feels better to me than (2), but is limiting in a similar way, if there's a lot of content in the tooltip. This is even more true for popovers.

For both (2) and (3), it is not possible to have nested content in the args passed to the function, unless a separate import is made for shiny.ui.

@jcheng5
Copy link
Collaborator

jcheng5 commented Jan 2, 2024

Easily option 1 for me, personally.

@cpsievert
Copy link
Collaborator Author

cpsievert commented Jan 2, 2024

Agreed (option 1), I'll update the PR accordingly

@wch wch merged commit a821c38 into main Jan 3, 2024
26 checks passed
@wch wch deleted the express-tooltip branch January 3, 2024 21:40
schloerke added a commit that referenced this pull request Jan 8, 2024
* main: (24 commits)
  Use dynamic version of py-shiny for deploy tests (#970)
  Add underscores to hide some imports (#978)
  Add rsconnect json files(shinyapps.io tests) and folium tests (#928)
  Express' `value_box()` no longer includes named positional args (#966)
  Include `tooltip()` and `popover()` in express (#949)
  Remove extra call to run_express()
  Call `tagify()` early to intercept `AttributeErrors` (#941)
  Don't pass sidebar twice to navbar_page
  Update changelog
  Update changelog
  Switch from `requests` to `urllib` (#940)
  Bump version to 0.6.1.1
  Fix docstring for page_opts
  Fix API doc sections for Express
  Smarter, lazier, and more complete page default/api for express (#893)
  Change `express.layout` to `express.ui` (#904)
  Remove `@output` from examples (#790)
  feat: Allow for `App` `server=` to take `input` only (#920)
  Add fixes for type stub generation (#828)
  Move quarto express docs to bottom
  ...
schloerke added a commit that referenced this pull request Jan 9, 2024
* main:
  Use dynamic version of py-shiny for deploy tests (#970)
  Add underscores to hide some imports (#978)
  Add rsconnect json files(shinyapps.io tests) and folium tests (#928)
  Express' `value_box()` no longer includes named positional args (#966)
  Include `tooltip()` and `popover()` in express (#949)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

shiny.express.ui is missing tooltip and popover
3 participants