This is an example of using leprechaun to build a shiny application.
Create an R package and scaffold a leprechaun application.
usethis::create_package('anApp')
leprechaun::scaffold()
Add sass to style the app.
leprechaun::use_sass()
We can then edit scss/_core.scss
to style all <h1>
tags.
$accent: #560bad;
html{
h1 {
color: $accent;
}
}
This requires the leprechaun::build()
step because the Sass
code must be compiled to CSS.
leprechaun::build()
Remember to always run leprechaun::build()
to see changes made
to the Sass reflected to the CSS.
JavaScript is better handled with packer, we therefore create a packer scaffold.
packer::scaffold_leprechaun()
Then we add the packer plugin.
leprechaun::use_packer()
This creates boiler plate code to use JavaScript with webpack, by default packer creates a custom handler to display an alert.
Like for Sass, this requires the build step to convert the ES6
from srcjs
to ES5 in the inst
.
leprechaun::build()
We can then use the convenience send_message
function to
send data to the front-end and display the alert.
# server.R
server <- function(input, output, session){
send_message <- make_send_message(session)
# send a message to show an alert
send_message("show-packer", text = "HELLO!")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.