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

experiment for JSX #72

Open
wants to merge 1 commit into
base: master
from
Open

Conversation

@timelyportfolio
Copy link

@timelyportfolio timelyportfolio commented Oct 20, 2016

This pull is solely intended as a point of discussion. It would be really nice (but probably an edge case) to be able to produce JSX. In JSX attributes are often unquoted JavaScript. To achieve this in a naive way with ugly code, I made the changes in this pull. I am willing to work much harder on this, but I want to make sure it is acceptable before I expend the effort.

Example

I am working on the reactR package that would ease working with React/JSX in R. As I was experimenting, since tags does not allow unquoted attributes, I currently have to do something like this.

library(htmltools)
library(reactR)

attachDependencies(
  browsable(
    tagList(
      tags$head(tags$script(src="//d3js.org/d3.v3.min.js")),
      tags$body(tags$script(babel_transform(
'
ReactDOM.render(
  <MicroBarChart data={[1,5,2,4]} hoverColor="rgb(161,130,214)"
  fillColor="rgb(210,193,237)" />,
  document.body
)
'
      )))
    )
  ),
  list(
    html_dependency_react(),
    htmlDependency(
      name="microbarchart",
      version="0.1",
      src=file.path(getwd(),"src"),
      script="react-micro-bar-chart.js"
    )
  )
)

It would be really nice since I am so spoiled by htmltools to do this instead.

htmltools::tag("MicroBarChart", list(data=noquote('{[1,5,2,4]}'), hoverColor="rgb(161,130,214)", fillColor="rgb(210,193,237)"))

which after this pull gives us this valid JSX.

<MicroBarChart data={[1,5,2,4]} hoverColor="rgb(161,130,214)" fillColor="rgb(210,193,237)"></MicroBarChart>
@timelyportfolio
Copy link
Author

@timelyportfolio timelyportfolio commented Jan 10, 2018

ping to see if there are any thoughts regarding this idea

@jcheng5
Copy link
Member

@jcheng5 jcheng5 commented Jan 10, 2018

Sorry this slipped through the net the first time. I like it. I'd maybe change the function/class name from noquote to something more unique, like rawattrib or something? noquote sounds like something out of the rlang package.

I'd also refactor the code slightly so we test for this case before testing for !is.na(attribValue), so you don't have to repeat the test twice.

@wch, any thoughts?

@timelyportfolio
Copy link
Author

@timelyportfolio timelyportfolio commented Jan 11, 2018

@jcheng5 no problem at all, I had considered it a long shot anyways but it sounds like maybe there is more chance than I thought. I chose noquote since it is built-in to R core, it implies what a user wants (in a different context though), and means we don't have to manage a new class or object. If you think another way of handling is better or more intuitive, I am happy to change. Also, makes sense on refactoring and will change after @wch comments.

Thanks!!!!!!!

@timelyportfolio
Copy link
Author

@timelyportfolio timelyportfolio commented Apr 20, 2020

any thoughts no this especially now that reactR is more viable for htmlwidgets and Shiny inputs?

@timelyportfolio
Copy link
Author

@timelyportfolio timelyportfolio commented Jun 26, 2020

one last effort - any hope?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.