Using Fomantic UI JavaScript elements [Advanced]
Appsilon
2024-04-18
Source:vignettes/fomantic_js.Rmd
fomantic_js.Rmd
Using Fomantic UI JavaScript elements [Advanced]
Some Fomantic UI elements require to run a specific JS code when DOM document is ready. There are at least 2 options to do this:
- Use
shinyjs
library(shinyjs)
...
jsCode <- " # Fomantic UI componts JS "
...
ui <- function() {
shinyUI(
semanticPage(
title = "Your page title",
shinyjs::useShinyjs(),
# Your UI code
)
)
}
server <- shinyServer(function(input, output) {
runjs(jsCode)
# Your Shiny logic
})
shinyApp(ui = ui(), server = server)
- Use
shiny::tags$script()
...
jsCode <- "
$(document).ready(function() {
# Semantic UI components JS code, like:
#$('.rating').rating('setting', 'clearable', true);
#$('.disabled .rating').rating('disable');
})
...
"
ui <- function() {
shinyUI(
semanticPage(
title = "My page",
tags$script(jsCode),
# Your UI code
)
)
}
...
server <- shinyServer(function(input, output) {
# Your Shiny logic
})
shinyApp(ui = ui(), server = server)