Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sortable Table doesn't work with observeEvent #97

Open
EkremBayar opened this issue Oct 25, 2023 · 1 comment
Open

Sortable Table doesn't work with observeEvent #97

EkremBayar opened this issue Oct 25, 2023 · 1 comment

Comments

@EkremBayar
Copy link

EkremBayar commented Oct 25, 2023

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)


@EkremBayar
Copy link
Author

EkremBayar commented Oct 25, 2023

I've changed renderTable part like this and it worked. It should be triggered by buttons.

 # Render Sortable
observe({
  input$sl_sort_submit
  input$sl_sort_cancel
  output$sl_sortable_table <- renderTable({rvData$SelectedPlayers})
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant