I have managed to build a shiny app that reads csv files in datatables but my problem is now making the output editable. I tried to use jquery.jeditable.js but it is not working. Below is the full code I built.
ui.R
library(shiny)
shinyUI(fluidPage(
titlePanel(""),
sidebarLayout(
sidebarPanel(
fileInput("file", "Upload the file",
accept=c('text/csv', 'text/comma-separated-values,text/plain')),
helpText("Default max. file size is 5MB"),
tags$hr(style="padding:0px;margin:0px")
),
mainPanel(
tags$div(id = "main", dataTableOutput("dtt"),
style = "font-size:85%; position: absolute; left: 150px; width:
1150px; top: 140px")),
tags$script(" $('#main').editable(function(value, settings) {
console.log(this);
console.log(value);
console.log(settings);
return(value);
}, {
type : 'text',
indicator : 'Saving...',
tooltip : 'Click to edit...'
});")
tags$head(tags$script(src="jquery.jeditable.js"))
)
)
))
server.R
library(shiny)
shinyServer(function(input, output, session){
data <- reactive({
file1 <- input$file
if(is.null(file1)){return()}
df <- read.csv(file = file1$datapath, header = TRUE, fill = TRUE)
})
output$dtt <-renderDataTable(data(),
extensions = 'Buttons',
selection = "multiple",
options = list(pageLength = 25, scrollX = TRUE, scrollY =
'500px',
dom = 'lBfrtip', buttons =
list(list(
extend = 'collection',
buttons = c('csv', 'pdf'),
text = 'Download'
))
))
})
All I had to do was update my DT r package in rstudios and that came along with the editing feature.