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

Support HTML in React context #66

Merged
merged 12 commits into from
Oct 2, 2023

Conversation

jakubsob
Copy link
Collaborator

Closes #13

Test app

library(shiny)
library(shiny.react)

shinyApp(
  ui = tagList(
    ReactContext(
      HTML(
        "<div style='font-weight: bold;'>Hello</div>"
      )
    ),
    reactOutput("react_output")
  ),
  server = function(input, output) {
    output$react_output <- renderReact({
      HTML(
        "<div style='font-weight: bold;'>Hello</div>"
      )
    })
  }
)

image

@kamilzyla Are there more cases which we should support?

@jakubsob jakubsob requested a review from kamilzyla March 27, 2023 09:30
@jakubsob jakubsob removed the request for review from kamilzyla August 28, 2023 13:03
@jakubsob jakubsob force-pushed the feature/13-support-html-in-react-context branch from 013ce7f to 655b456 Compare August 28, 2023 13:07
@codecov-commenter
Copy link

codecov-commenter commented Aug 28, 2023

Codecov Report

Merging #66 (a7ae791) into main (6e2e837) will increase coverage by 62.57%.
The diff coverage is 100.00%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the GitHub App Integration for your organization. Read more.

@@            Coverage Diff             @@
##            main      #66       +/-   ##
==========================================
+ Coverage   9.72%   72.29%   +62.57%     
==========================================
  Files          5        5               
  Lines        144      148        +4     
==========================================
+ Hits          14      107       +93     
+ Misses       130       41       -89     
Files Changed Coverage Δ
R/reactData.R 52.17% <100.00%> (+45.03%) ⬆️

... and 4 files with indirect coverage changes

@averissimo averissimo self-assigned this Aug 29, 2023
Copy link
Contributor

@averissimo averissimo left a comment

Choose a reason for hiding this comment

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

Cool new feature for {shiny.react} 🎸

I have 2 comments on the PR.

  1. NAMESPACE is missing the exported function and is not detecting html classes in asReactData method, defaulting to asReactData.default
    • needs devtools::document()
  2. The isHTML(str) is too broad and is parsing text that contains a tag in it.
    • The function and call can probably be removed as it works without them
      • 🟡 Unless I'm missing a required feature that will parse any string that contains a html tag

Reproducible example for testing my comments on 2.

pkgload::load_all()
library(shiny)
library(shiny.react)

shinyApp(
  ui = tagList(
    ReactContext(
      HTML(
        "<div style='font-weight: bold;'>Hello <span style='font-weight: normal;'>my friend</span></div>"
      )
    ),
    ReactContext(
      "<div style='font-weight: bold;'>Hello (just plain text)</div>"
    ),
    reactOutput("react_output")
  ),
  server = function(input, output) {
    output$react_output <- renderReact({
      HTML(
        "<div style='font-weight: bold;'>Hello (renderReact)</div>"
      )
    })
  }
)

Screenshot of what I understand to be the expected result

image

R/reactData.R Show resolved Hide resolved
js/src/react/mapReactData.js Outdated Show resolved Hide resolved
js/src/react/mapReactData.js Outdated Show resolved Hide resolved
@jakubsob
Copy link
Collaborator Author

jakubsob commented Sep 1, 2023

Thanks @averissimo, that was great review. I resolved your comments and added a few shinytest2 tests to capture this behavior that is implemented in this PR. PTAL 😉

Copy link
Contributor

@averissimo averissimo left a comment

Choose a reason for hiding this comment

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

LGTM!! 💯

Great that you added the test!

Sorry for the delay, I thought I already approved this ages ago.

@jakubsob jakubsob merged commit d32126c into main Oct 2, 2023
1 check passed
@jakubsob jakubsob deleted the feature/13-support-html-in-react-context branch October 2, 2023 13:07
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.

Add support for HTML() within React
3 participants