rshinycrudgooglesheets4

Deleting always the first row in a shiny CRUD app only after adding preexsitent data


I am stuck and need help.

I am working with this gist https://gist.github.com/gluc/d39cea3d11f03542970b

Basically in a shiny app it provides the possibility to make CRUD maneuvers and it works perfect.

I now managed to store the data on googlesheets and also to load the data in with: read_sheet function from googlesheets4 package.

The issue is if I want to delete the last row of the table within the shiny app the first row is deleted after pressing the delete button.

This problem occurs only if I load in preexistend data (in my case from googlesheets). I have encountered the problem: The id is not updating when I click the rows in the shiny app table.

I have used browser() and went through each function but I can't find the problem.

If I click on first row and delete the first row everything works perfect, but clicking the second or any other row except the first, always the first row is deleted.

Update: I think the main issue is that after reading in the data from gogglesheets the disabled Id field is not navigating with the table, see picture.

If I click row 3 then the Id field should be 3 but it stays at 1 all the time. Therefore any action (for example deleting) on the table removes row one.

I can't get the link between the dataframe that is loaded at the beginning in the environment and the data that is defined by the CRUD application. The idea of akrun is perfect and should work but it does not:

I assign at the beginning of the code the read_sheet(...) table to responses like:

df_id_read_sheet <- read_sheet("......")
responses <- df_id_read_sheet

enter image description here


Solution

  • After one night without sleep. I found the solution. And it was as simple as I thought. Following one of the first advice by dear @akrun I checked with str the structure of the loaded googlesheet.

    The sheet is imported as tibble after transforming it to data.frame and assigning to responses the complete code worked as expected. The isssue arised because of the rownames.

    Using browser() immediately after assigning the sheet to responses I was able to see and check the structure within the shiny app on my console.

    I really love debuging with broswer() as it enables me to see what is going on in shiny apps also.

    Here is the simple yet hard discovered solution: At the beginning of your shiny app code:

    library(magritter)
    
    df_id_read_sheet <- read_sheet("put your sheet id here")
    responses <- df_id_read_sheet
    responses %<>% 
      as.data.frame()