Skip to content

Sortable Table doesn't work with observeEvent #97

@EkremBayar

Description

@EkremBayar

Hi,

I have a simple app below. There is a "Sort" button and it opens a modalDialog. I want to sort my table on this modal dialog. After I finished sorting, I will click submit button or cancel button and it removes modal dialog. There is nothing wrong for now. However, if you click "Sort" button twice, sortable table loses its features and becomes a normal table. That's why, you can't sort your table.

How can I fix this issue?

Thanks in advance.

library(shiny)
library(shinyjqui)

data <- head(mtcars)

ui <- fluidPage(
  
  # Action Button
  actionButton("sl_player_sort","Sort")
  
)

server <- function(input, output, session) {
  
  # Show modal with action button  
  observeEvent(input$sl_player_sort, {

    showModal(
      modalDialog(
        title = "Sort",
        size = "l",
        
        # Sortable Output
        sortableTableOutput("sl_sortable_table"),

        easyClose = FALSE,

        # Submit & Cancel Button
        footer = tagList(
          div(
            style = "text-align:center;",
            actionButton("sl_sort_submit", "Submit", style = "background-color:#39a642; color:white"),
            actionButton("sl_sort_cancel", "Cancel", style = "text_align:center;background-color:red; color:white")
          )
        )
      )
    )
    
  })
  
  # Render Sortable
  output$sl_sortable_table <- renderTable({data})
  
  # Reorder Data with Sortable & Submit
  observeEvent(input$sl_sort_submit, {
    data<- data[input$sl_sortable_table_order,]
    removeModal()
  })
  
  # Cancel
  observeEvent(input$sl_sort_cancel, {
    removeModal()
  })
}

shinyApp(ui, server)


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions