How to add/delete new data to a datatable in a shiny application?

I'm new to Shiny as of now and am building a shiny app on the mtcars dataset. The following functionalities should be there -

  1. Although I have figured out how to edit existing data using the editable option in the renderDataTable function, I can't figure out how to add or delete rows to the table.
  2. Although the data can be exported, yet I find that only the page I'm on in the app can only be exported.
  3. I would like to compare multiple rows in a new tab after selecting them from the data table tab. Thus I should get an option of selecting a baseline car and others as alternates.
  1. For this one it seems like you'd have to create some custom buttons w/ Shiny to add/delete rows to the table. This SO solution has a nice method for implementing a "Delete Selected Rows" button.
  2. Set the server argument in your renderDT() function to FALSE
  3. Can you elaborate on this a bit more? I don't think I understand what your goal is.

Hi Ben,

Thank you for your reply.

For the third question my objectives are as follows -

The mtcars dataset has data on various cars. My goal is to compare one car to another. For basic understanding, for now let us consider the goal to -
I) Select two or more rows from the data table one of which will be the baseline for comparison.
II) The selected rows upon clicking a "compare" button should open in a new tab of the app i.e., a new tab where we will now have a data table with just the selected rows
III) Finally we would like to create further metrics on the new tab with the help of which we will be able to compare the selected cars against the first car we chose as a baseline for comparison.

Thanks for elaborating. The "new tab" functionality you're looking for might be more work than it's worth. If you can live with two tables in one screen (Table 1: baseline table, Table 2: comparison table) then you could probably achieve the functionality by updating the data in Table 2 based on what's clicked in Table 1. You can find more info on getting the values of the selected rows in this section of the DT documentation..

If you really need the "new tab" functionality, then diving into handling URL query string in Shiny could be a solution but again this might get very tricky quickly.

Thanks! I'll take a look at this and come back for further queries.

The delete action button is working now.
Also found a way to add an empty row to the data table using dataTableProxy() and then using editable function to add new data to the empty rows

1 Like

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.