Happy Monday!
While using the package sortable, I need to return the order of the box 'id' instead of the 'Title' of the box. Secondly, as each box will be dynamically generated via insertUI and also have a component that will remove each box. I need to wrap each box in a tags$div(). However, when I include the div wrap I lose the ability to properly sort/drag and drop.
## Example shiny app with correct sorting. No Div tag around boxes.
library(shiny)
library(tidyverse)
library(sortable)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
fluidPage(
div(
id = "sortable",
box(id = "id1", title = "Test1",solidHeader = T, width = 12, actionButton('btntest1', "btn 1")),
box(id = "id2", title = "Test2",solidHeader = T, width = 12, actionButton('btntest2', "btn 2")),
box(id = "id3", title = "Test3",solidHeader = T, width = 12, actionButton('btntest2', "btn 3")),
box(id = "id4", title = "Test4",solidHeader = T, width = 12, actionButton('btntest2', "btn 4"))
),
verbatimTextOutput("chosen"),
sortable_js(
css_id = "sortable",
options = sortable_options(
onSort = sortable_js_capture_input(input_id = "selected"),
onLoad = sortable_js_capture_input(input_id = "selected")
)
)
)#fluidPage
)
)
server <- function(input, output) {
output$chosen <- renderPrint(str_split(input$selected, "\n",simplify = T)[,1])
}
shinyApp(ui, server)
## Example shiny app with div tag around box, sorting does not work.
library(shiny)
library(tidyverse)
library(sortable)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
fluidPage(
tags$div(id = "sortable",
tags$div(id = "id",
box(title = "Test1",solidHeader = T, width = 12, actionButton('btntest1', "btn 1"))
),
tags$div(id = "id",
box(title = "Test2",solidHeader = T, width = 12, actionButton('btntest2', "btn 2"))
),
tags$div(id = "id",
box(title = "Test3",solidHeader = T, width = 12, actionButton('btntest3', "btn 3"))
)
),
verbatimTextOutput("chosen"),
sortable_js(
css_id = "sortable",
options = sortable_options(
onSort = sortable_js_capture_input(input_id = "selected"),
onLoad = sortable_js_capture_input(input_id = "selected")
)
)
)#fluidPage
)
)
server <- function(input, output) {
output$chosen <- renderPrint(str_split(input$selected, "\n",simplify = T)[,1])
}
shinyApp(ui, server)