Skip to content

Conversation

@JohnCoene
Copy link
Contributor

This is a suggestion to fix #3995.

  1. We use .html() client-side (instead of .text())
  2. R-side, we check if label is NULL if not we convert to character

@JohnCoene
Copy link
Contributor Author

Note: I only include srcts and R file, I did not commit the generated JavaScript, let me know if I should.

@cpsievert
Copy link
Collaborator

Thanks @JohnCoene, would you mind looking into the test failures (and fixing them)?

@JohnCoene
Copy link
Contributor Author

@cpsievert I believe it's good now.

Comment on lines 359 to 360
const emptyLabel =
Array.isArray(labelContent.html) && labelContent.html.length === 0;
Copy link
Collaborator

@cpsievert cpsievert Mar 15, 2024

Choose a reason for hiding this comment

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

I think this check might also now need to check for empty string? I noticed that this PR will break this "clear label" feature:

library(shiny)

ui <- fluidPage(
  checkboxInput("id", label = "foo")
)

server <- function(input, output, session) {
  updateCheckboxInput(inputId = "id", label = character(0))
}

shinyApp(ui, server)

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 good catch. Do we still need Array.isArray check? I'm not sure what's for to be honest; could we/can we pass a vector of length greater than 1 to label?

Asking because I wonder if it can't be simplified to just labelContent.html.length == 0 since "".length == 0 is true

Copy link
Collaborator

@cpsievert cpsievert Jun 16, 2025

Choose a reason for hiding this comment

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

Good point, I believe we can. Done in 6b97b63

It does make me realize that, with this PR updateFooInput(label = "") will now display:none the label container, which feels more like a feature than a bug

@cpsievert
Copy link
Collaborator

@JohnCoene I noticed #3996 (comment) when having a look into modifying one of our testing apps to account for this feature. I've got a start on that here rstudio/shinycoreci#262 and it'd be awesome if you wanted to review/fix/improve that test app.

@JohnCoene
Copy link
Contributor Author

Is there anything else I c an do on this PR?

@cpsievert
Copy link
Collaborator

cpsievert commented Apr 8, 2024

Thanks @JohnCoene, please add a NEWS item, then this should be good to merge.

That said, it'd also be great to update our 158-input-labels test to have test coverage of this change (a minimal, still failing, proposal is in rstudio/shinycoreci#262). If you're feeling up to the task, you could also take that PR over the finish line. To run the relevant test locally:

cd shinycoreci/inst/apps/158-input-labels
R -e "shiny::runTests()"

Screenshot differences are to be expected -- as long as the screenshot changes look good locally and there are no other failures than we can merge that PR as well

@cpsievert cpsievert requested a review from Copilot June 16, 2025 15:27

This comment was marked as off-topic.

@cpsievert cpsievert merged commit db9f210 into rstudio:main Jun 16, 2025
12 checks passed
cpsievert added a commit that referenced this pull request Jun 19, 2025
cpsievert added a commit that referenced this pull request Jun 19, 2025
cpsievert added a commit that referenced this pull request Jun 20, 2025
* Follow up to #3996: fix front-end checkbox label updating logic

* More descriptive name
cpsievert added a commit that referenced this pull request Jun 26, 2025
* Close #4239: fix front-end action button label updating logic (follow up to #3996)

* Update news

* Use a separator instead of putting markup in attributes

* `yarn build` (GitHub Actions)

* Address feedback

* Cleanup

* Refactor into a single method to split icon/label

* `yarn build` (GitHub Actions)

* Better naming

* Add some padding to the separator

* Add some unit tests for R logic

* Update NEWS.md

* Update NEWS.md

* Update NEWS.md

* Update NEWS.md

* Increase backcompat (keep same R structure when no icon is provided)

* Refine comment

---------

Co-authored-by: cpsievert <cpsievert@users.noreply.github.com>
schloerke added a commit that referenced this pull request Jul 6, 2025
* main: (32 commits)
  Revert the addition of spacing between `icon` and `label` in `actionButton()` (#4248)
  Restrict `icon`/`label` separator spacing to `actionButton()` (#4247)
  Fix front-end action button label updating logic (#4242)
  Update news
  Properly handle undefined value for input subscribe callback (#4243)
  Start new version (#4241)
  v1.11.0 release candidate (#4232)
  Follow up to #3996: fix front-end checkbox label updating logic (#4238)
  feat(InputBinding): subscribe callback now supports event priority (#4211)
  Follow up to #3996 when label is unspecified (i.e., NULL), don't include it in the message (#4237)
  Run routine (#4234)
  chore: #4175 update jquery-ui to 1.14.1 (#4205)
  Update jQuery to 3.7.1 (#3969)
  Fix 404 in example 08_html (shiny.min.css) (#4221)
  Follow up to #3870: fix location of news item (#4233)
  Bugfix for error found in tests (#3870)
  Allow update input labels with HTML (#3996)
  Adds mirai to documentation (#4230)
  family->given for R Core authorship (#4222)
  fix(renderPlot): get interactive plotting working with ggplot2 v4.0 (#4228)
  ...
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.

Update input - HTML in label

3 participants