Skip to content

Instantly share code, notes, and snippets.

@saurfang
Last active May 8, 2019 22:53
Show Gist options
  • Save saurfang/6684a66601a7e5b6467f to your computer and use it in GitHub Desktop.
Save saurfang/6684a66601a7e5b6467f to your computer and use it in GitHub Desktop.
Selectize Plugins in Shiny
library(htmltools)
addUIDep <- function(x) {
jqueryUIDep <- htmlDependency("jqueryui", "1.10.4", c(href="shared/jqueryui/1.10.4"),
script = "jquery-ui.min.js",
stylesheet = "jquery-ui.min.css")
attachDependencies(x, c(htmlDependencies(x), list(jqueryUIDep)))
}
shinyApp(
ui = fluidPage(
addUIDep(selectizeInput("variables", "", letters, c("a","b","c"), TRUE,
options = list(plugins = list("drag_drop", "remove_button")))),
textOutput("variables")
),
server = function(input, output) {
output$variables <- renderText(input$variables)
}
)
@thomascjohnson
Copy link

Super helpful! Thanks!

@r2evans
Copy link

r2evans commented May 8, 2019

The current shiny (perhaps even since 1.2.0) seems to be shipped with everything already included, so that all you should need is:

library(shiny)
library(htmltools)

shinyApp(
  ui = fluidPage(
    selectizeInput("variables", "", letters, c("a","b","c"), TRUE, 
                   options = list(plugins = list("drag_drop", "remove_button"))),
    textOutput("variables")
  ), 
  server = function(input, output) {
    output$variables <- renderText(input$variables)
  }
)

(No more need to inject the HTML dependencies. Nice!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment