Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you use R's native data editor to edit a csv from within Shiny?

Tags:

r

shiny

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.

like image 845
Jonathan Avatar asked Jan 29 '26 10:01

Jonathan


1 Answers

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

like image 76
Pork Chop Avatar answered Jan 30 '26 22:01

Pork Chop