Ashley Baldry
{shiny} + JS =
❤️tags$script(HTML("
$(document).ready(function() {
$('[data-toggle="tooltip"]').tooltip()
})
"))
tags$script(src="custom.js")
Shiny.inputBindings.register(inputBinding, "your.inputBinding")
Latest version: https://ashbaldry.shinyapps.io/designer/
srcjs
.Rbuildignore
srcjs
directory up in your IDEnpm init
in the terminal and initialise your projectnpm
, within its installation
npm install github:rstudio/shiny
npm install @types/jquery@3.5.14
import { build } from 'esbuild'
build({
entryPoints: ['index.js'],
bundle: true,
sourcemap: true,
outfile: '../inst/app/www/designer.min.js',
platform: 'node',
minify: true
}).catch(
() => process.exit(1)
)
npm install esbuild --save-dev
--save-dev
only includes package for development purposesnpm install eslint --save-dev
.eslintrc.yml
"type": "module"
to package.json to enable import
to work// component/component.js
export class Component {
html = '<div></div>'
constructor () {
// runs when class is created
}
createComponent () {
return this.html
}
}
// component/button.js
import {Component} from './Component'
class Button extends Component {
html = '<button ...>...</button>'
constructor () {
// runs Component constructor
super()
}
}
Component
class contains several methods accessible to individual components// component/component.js
export class Component {
html = '<div></div>'
constructor () {
// runs when class is created
}
createComponent () {
return this.html
}
}
// component/button.js
import {Component} from './Component'
class Button extends Component {
html = '<button ...>...</button>'
constructor () {
// runs Component constructor
super()
}
}
__tests__
directory.test.js
npm install --save-dev jest
npm install --save-dev @babel/plugin-transform-modules-commonjs
// component/button.js
import Component from 'Component'
class Button extends Component {
html = '<button ...>...</button>'
constructor = {
// runs Component constructor
super()
}
}
// component/__tests__/Button.test.js
import { Button } from '../Button'
test('sanity test - button constructs successfully', () => {
const button = new Button()
expect(button.html).toBe('<button ...>...</button>')
})
Include JavaScript unit tests as part of your GitHub Actions
JavaScript unit test results of the {designer} package
Test Suites: 32 passed, 32 total
Tests: 38 passed, 38 total
Snapshots: 0 total
Time: 5.948 s
Ran all test suites.
Done in 6.82s.