I use DT::renderDataTable to render a data table for a Shiny app and I use editable = TRUE in the definition of datatable(). The data argument of datatable is a reactive expression that gets data from a database based on the selected value from a dropdown menu. I want to be able to have a button that refreshes the datatable and discards any user edits, just like selecting another value from the dropdown menu. I can't give you a reproducible example because I am using proprietary code and data that come from a database. I know I can use an observeEvent on the refresh button click event and then call the render function of the table, but I am looking for a more elegant approach. Thanks
Asked
Active
Viewed 47 times
0
Stelios M
- 150
- 1
- 1
- 9
-
Will something like this solve your problem: [add a page refresh button by using rshiny](https://stackoverflow.com/questions/30852356/add-a-page-refresh-button-by-using-r-shiny) – DS_UNI Mar 13 '19 at 08:36
-
You can add a choice `Discard all` that render the original data and test for it inside your `DT::renderDataTable` – Clemsang Mar 13 '19 at 08:37
-
@Clemsang can you elaborate on that? I am not sure I follow you. – Stelios M Mar 13 '19 at 12:35
-
You add a choice to the drop down. If the drop down is `Discard all`, you render the initial data, else you modifiy as usual the current data and render it – Clemsang Mar 13 '19 at 12:49
1 Answers
0
Found out that you can use proxy <- datatableProxy() and then reloadData(proxy) inside the observeEvent of the refresh button. This would cancel any datatable edits made.
Stelios M
- 150
- 1
- 1
- 9