JohnCoene / javascript-for-r-comments

1 stars 0 forks source link

Question pertaining to play(shiny::h2("Chocolate is a colour", style = "color:chocolate;")) #38

Open MayaGans opened 3 years ago

MayaGans commented 3 years ago

Hey John! This isn't a note for the book as much as it is a general question but I have a question but essentially my mental model after being a little over halfway through the book is that htmlwidgets allows you to supply data through R and pass that to a JS object.

....What if I want to add some html in the mix? For instance I was wondering in the first example play(shiny::h2("Chocolate is a colour", style = "color:chocolate;")) how would I update the play function so that the user only needs to supply the message, and it's always a chocolate <h2> ?

I was thinking I could add some kind of htmltools::tags$h2(....) but I'm not quite sure how that'd work.

Does this make sense? Any tips/helps appreciated!

JohnCoene commented 3 years ago

Well, that was one thing that was not perfectly clear if I remember correctly, hopefully I've clarified that in the book here. It was probably slightly different when you read that part.

You could, of course, within the play function with: sprintf("<h2>%s</h2>", message) but that's probably not ideal. I created an example in a repo to which I'll invite you in a minute.

MayaGans commented 3 years ago

Ah wonderful! Perfect excuse to reinforce the earlier chapters and read the book again, thank you!!!

JohnCoene commented 3 years ago

No no, thank you for the feedback!