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

bug if used inside a modal #24

Open
ShinyFabio opened this issue Jul 9, 2021 · 9 comments
Open

bug if used inside a modal #24

ShinyFabio opened this issue Jul 9, 2021 · 9 comments

Comments

@ShinyFabio
Copy link

Hi again,
I've found a bug if I use the package inside a modal. Here's the code where you can reproduce the error. The bug appears if you try to change the column names or the row names.

if (interactive()) {
  ui <- fluidPage(
    actionButton("upaziendedata", "Aggiorna i dati"),
    shinyBS::bsModal("upaziendetab", "Tabella", trigger = "upaziendedata", size = "large",
    dataInputUI("input-1"),
    dataOutputUI("output-1"),
    dataEditUI("edit-1")
  ))
  
  server <- function(input, output, session) {
    data_to_edit <- dataInputServer("input-1")
    data_to_edit2 <- dataEditServer("edit-1",
                                    data = data_to_edit
    )
    dataOutputServer("output-1",
                     data = data_to_edit2
    )
  }
  
  shinyApp(ui, server)
}

I notice that you use the {rhandsontable} package. Maybe this can be useful:
https://stackoverflow.com/questions/52697624/handsontable-in-shiny-modal-does-not-render-properly

@DillonHammill
Copy link
Owner

DillonHammill commented Jul 10, 2021

This doesn't look like a rhandsontable issue. I suspect that it has something to do with the JavaScript code that I added to allow the editing of row/column headers - for some reason it is not being invoked within the modalDialog window. Due to my limited JS knowledge, I will need to ask for some external help if we are going to get this to work properly.

I remember @timelyportfolio helped me to get this JS code working a while back (jrowen/rhandsontable#344). Unfortunately I don't know anyone else who may be able to figure this one out. @timelyportfolio any chance that you would you be able to take a look at this when you get time? The relevant code is in the dataEdit module: https://github.com/DillonHammill/DataEditR/blob/master/R/dataEdit.R

@lgirola
Copy link

lgirola commented Jul 24, 2021

Hi,

I'm having issues with running rhandsontable from within a modal too.

When rhandsontable is rendered in a modal box, depending on the circumstance only a part of the table is rendered until the user clicks on the partially rendered table. Is this a bug, or am I using rhandsontable incorrectly? Please see super simple MWE code below. It renders the initial table just fine, but when the user makes a change to the table (for example inserting a row with data) and tries re-rendering it by clicking the "Show" action button, only part of the table is rendered until the user clicks on the table.

The first image below shows the rendered table when first invoking the app - looks good. The second image shows the rendered table after having inserted a row/data and then clicking "Show" -- I only get a partial rendering of the table until clicking on it, and then the complete table pops up (as it should have done after the "Show" click). The third images shows the completely and correctly rendered table after inserting a 3rd row, after clicking "Show", and after clicking on the partially rendered table.

library(shiny)
library(rhandsontable)

ui <- fluidPage(actionButton("show","Show"), 
                actionButton("reset","Reset"))

server <- function(input,output,session){

  dat <- reactiveVal(data.frame(x=runif(2),y=runif(2)))
  
  observeEvent(input$show,{showModal(modalDialog(rHandsontableOutput("hot")))})
  
  observeEvent(input$reset,dat(data.frame(x=runif(2),y=runif(2))))
  
  output$hot <- renderRHandsontable(rhandsontable(dat()))

  } # close Server

shinyApp(ui,server)

Image1
Image2
Image3

@lgirola
Copy link

lgirola commented Jul 28, 2021 via email

@timelyportfolio
Copy link

please see jrowen/rhandsontable#387 as a step toward a solution

@DillonHammill
Copy link
Owner

Thanks so much for looking into this @timelyportfolio! Do you mind taking a look at the original issue as well (i.e. the row/column editing). I have done some additional testing and if I click on a column name I cannot edit it in the modal dialog, but if I close the dialog the cell for the column name that I wanted to edit appears (i.e. column headers shown in mainPage() rather than modal). Perhaps this is related to the z-index? Is there a way to increase it just for column and row headers?

I am happy to add you as a contributor to this project if you would be interested.

@DillonHammill
Copy link
Owner

@timelyportfolio, I have tried increasing the z-index in the dataEdit module to 10000. If I do this the box to edit the column headers does appear, however I am unable to edit the text. Perhaps I need to up the z-index for other components as well?

'z-index:1000;' +

@ShinyFabio
Copy link
Author

Hi Dillon, I saw this solution:

please see jrowen/rhandsontable#387 as a step toward a solution

Do I have to implement it in my code, or I have to wait a version of your package with this bugfix? Because, for example, if I use dataEditServer() and dataEditUI() to display the table, I don't have to use the renderRHandsontable() function.

@DillonHammill
Copy link
Owner

@ShinyFabio, unfortunately this won't fix your original issue related to editing of column/row names in modal dialogs. As I mentioned above this is quite complicated and I have not yet been able to get it to work. You will also notice that the proposed solution does not work in all instances - I hope that a more permanent fix will come in the near future. For now, I think I will leave the code in DataEditR as is - I would recommend using a tabular design in your application if you need to display data on separate pages.

@ShinyFabio
Copy link
Author

I tried also to set col_names = FALSE but when I click on a column name (for example to select the entire column) the problem is still there. We will hope for a fix !

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

4 participants