3

Much like the edit function in R, I would like to manually make changes to a data frame from within Shiny. I have been to the shiny website

http://shiny.rstudio.com/gallery/datatables-options.html

however, I have not find a place where I can manually change data.

Jonathan
  • 611
  • 2
  • 7
  • 15
  • Have you tried looking at [this post](http://stackoverflow.com/questions/27636931/how-to-implement-inline-editing-on-datatables-in-r-shiny) and [this one](http://stackoverflow.com/questions/17263627/shiny-r-application-that-allows-users-to-modify-data)? – HubertL Feb 10 '16 at 19:38
  • Yes, trestletech package has not been updated in awhile and I couldn't get it to install. While the second one provides a theoretical answer, which doesn't have a concrete solution, which is why I posted the question. But we're definitely on the same page – Jonathan Feb 10 '16 at 21:59

1 Answers1

3

you can do what you want with shinysky package. It offer functionality to edit your tables on demand. Below is a simple example with mtcars dataset where you can change the table content and then download the updates you introduced during the session. You can easily add the file input to read .csv files yourself

rm(list = ls())
library(shiny)
library(shinydashboard)
library(shinysky)

ui <- dashboardPage(
  dashboardHeader(title = "How to edit a table"),
  dashboardSidebar(sidebarMenu(id = "tabs",menuItem("Menu Item 1", tabName = "one", icon = icon("dashboard"))
  )),
  dashboardBody(
    tabItems(tabItem(tabName = "one",hotable("hotable1"),downloadButton('downloadData', 'Download')))
    ))

server <- function(input, output) {

  previous <- reactive({mtcars})
  sample_data <- reactive({

    if(is.null(input$hotable1)){return(previous())}
    else if(!identical(previous(),input$hotable1))
    {
      sample_data <- as.data.frame(hot.to.df(input$hotable1))
      sample_data
    }
  })
  output$hotable1 <- renderHotable({sample_data()}, readOnly = F)
  output$downloadData <- downloadHandler(filename = function() {paste(Sys.time(), '- My New Table.csv', sep='') },content = function(file) {write.csv(sample_data(), file, row.names = FALSE)})
}
shinyApp(ui, server) 

enter image description here

The downloaded file looks like so:

enter image description here

PeterVermont
  • 1,922
  • 23
  • 18
Pork Chop
  • 28,528
  • 5
  • 63
  • 77
  • For some reason I couldn't get the downloaded file, it never game me an option to choose the file type. Everything else was very smooth after downloading shinysky – Jonathan Feb 11 '16 at 19:44
  • As per my example, everything should work. If you're using additional code, that might be breaking it. For the download, please refer to `downloadHandler` where I specified it would automatically download `.csv` format – Pork Chop Feb 12 '16 at 07:56
  • Problem solved: I had to change run App to run External in RStudio – Jonathan Feb 14 '16 at 22:28