Skip to content

Instantly share code, notes, and snippets.

@vnijs
Last active February 5, 2023 07:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vnijs/2e6eec27eaea12beec00 to your computer and use it in GitHub Desktop.
Save vnijs/2e6eec27eaea12beec00 to your computer and use it in GitHub Desktop.
Example of selectize drag-and-drop in Shiny 0.12.2.9000 or higher
library(shiny)
library(DT)
dat <- mtcars
shinyServer(function(input, output, session) {
output$ui_view_vars <- renderUI({
vars <- colnames(dat)
## using selectizeInput with drag_drop and DT
selectizeInput("view_vars", "Select variables to show:", choices = vars,
selected = vars, multiple = TRUE,
options = list(plugins = list('remove_button', 'drag_drop')))
})
output$dataviewer <- DT::renderDataTable({
if (is.null(input$view_vars)) return()
DT::datatable(dat[,input$view_vars])
})
})
shinyUI(fluidPage(
sidebarLayout(
sidebarPanel(
uiOutput("ui_view_vars")
),
mainPanel(
tabPanel("View", DT::dataTableOutput("dataviewer"))
)
)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment