I don't think there is a way to save the sorted columns in DataTables for brilliant, Sad!
With the code below, I can save the changes made in a brilliant application to the mtcars2.csv
file. Interesting! sorting by the desired column, clicking on any data cell and pressing the enter key saves the row order in mtcars2.csv
. Accept the timelyportolio
tag when submitting a problem to git.
R Code:
library(shiny) library(rhandsontable) runApp(shinyApp( ui = fluidPage(titlePanel("Edit Data File"), helpText("Changes to the table will be automatically saved to the source file."), # actionButton("saveBtn", "Save"), rHandsontableOutput("hot")), shinyServer(function(input, output, session) { values = reactiveValues() data = reactive({ if (is.null(input$hot)) { hot = read.csv("mtcars.csv", stringsAsFactors = FALSE) } else { hot = hot_to_r(input$hot) } # this would be used as a function input values[["hot"]] = hot hot }) observe({ # input$saveBtn if (!is.null(values[["hot"]])) { write.csv(values[["hot"]], "mtcars.csv", row.names = FALSE) } }) output$hot <- renderRHandsontable({ hot = data() if (!is.null(hot)) { hot = rhandsontable(hot) %>% hot_table(highlightCol = TRUE, highlightRow = TRUE) %>% hot_cols(columnSorting = TRUE) hot } }) }) ))
source share