html_dependency_mobx | R Documentation |
Add JavaScript 'mobx' and 'mobx-react' dependency. When using with 'react', the order
of the dependencies is important, so please add html_dependency_react()
before
html_dependency_mobx()
.
html_dependency_mobx(react = TRUE)
react |
|
htmlDependency
if(interactive()) {
library(htmltools)
library(reactR)
browsable(
tagList(
html_dependency_mobx(react = FALSE),
div(id="test"),
tags$script(HTML(
"
var obs = mobx.observable({val: null})
mobx.autorun(function() {
document.querySelector('#test').innerText = obs.val
})
setInterval(
function() {obs.val++},
1000
)
"
))
)
)
}
## Not run:
# use with react
library(htmltools)
library(reactR)
browsable(
tagList(
html_dependency_react(),
html_dependency_mobx(),
div(id="test"),
tags$script(HTML(babel_transform(
"
var obs = mobx.observable({val: null})
var App = mobxReact.observer((props) => <div>{props.obs.val}</div>)
ReactDOM.render(<App obs = {obs}/>, document.querySelector('#test'))
setInterval(
function() {obs.val++},
1000
)
"
)))
)
)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.