5

I have researched a lot on the issue already, but so far no solution has been provided when using shiny's showModal() instead of bsModal().

When I show a rhandsontable in a modal Dialog for the second time, the display is buggy, i.e. not all columns are displayed.

An example below:

library(shiny)
library(rhandsontable)

u <- shinyUI(fluidPage(

  # Will show first pop-up
  actionButton("go", "Show Table")

))

s <- shinyServer(function(input,output,session){

  df <- data.frame(Wnr = 1:10)  

  observeEvent(input$go, {

    output$table <- renderRHandsontable({

      rhandsontable(df, width = "100%", height = 200)

    })

    showModal(modalDialog(

      title = "Table",
      rHandsontableOutput("table"),
      footer = tagList(actionButton("go2", "Continue"),
                       modalButton("Stop"))

    ))
  })

  observeEvent(input$go2, {

    removeModal()

    # Recalculate the table, adding new columns
    output$table <- renderRHandsontable({

      df$AC <- 1
      df$BC <- 2

      rhandsontable(df, width = "100%", height = 200)

    })

    showModal(modalDialog(

      title = "Table",
      rHandsontableOutput("table"),
      footer = tagList(actionButton("go2", "Continue"),
                       modalButton("Stop"))


    ))
  })


})

shinyApp(u,s)

Is there a way (potentially using JavaScript) to fix this display bug? It seems that the $("myModal").on({"shown.bs.modal", ...}) trick doesn't work with shiny modals because they are differently structured than bootstrap modals from the shinyBS package. A reason why I don't use the shinyBS package is that I cannot add customized action buttons to the footer of the modal. So if you find a way solving it with shinyBS, I am happy too. Ideally, however, I would prefer a solution using modalDialog().

I appreciate any help! Let me know if more information is needed

Tobias Krabel
  • 656
  • 4
  • 8

0 Answers0