I have tried for days to figure out how to add an empty row to the DataTable and the data set on the server side this is the closest I got but it still does not work, I'm not sure what's wrong since its not returning any errors.
library(shiny)
library(DT)
library(readxl)
library(ggplot2)
library(writexl)
library(readxl)
library(magrittr)
library(dplyr)
library(tidyr)
dt_output = function(title, id) {
fluidRow(column(
5, h1( title)), hr(), DTOutput(id)
)
}
render_dt = function(data, editable = 'cell', server = TRUE, ...) {
renderDataTable(data(), server =TRUE , selection = list(target = 'row'),editable = editable,filter = list(
position = 'top'),...)
}
ui<- fluidPage(
actionButton("add", "Add"),
dt_output('Dining Protocol Data', 'x1')
)
server <- function(input,output,session){
data<- reactive({data.frame(read_excel("Dining protocol database Official.xlsx"))})
?renderDataTable
output$x1 = render_dt(data(), 'cell')
proxy5 = dataTableProxy('x1')
observeEvent(input$x1_cell_edit, {
str(input$x1_cell_edit) # check what info looks like (a data frame of 3 columns)
d5 <<- editData(data(), input$x1_cell_edit)
replaceData(proxy5, d5, resetPaging = FALSE)
})
user_table <-reactive({
data() %>%
slice(1) %>%
# transpose the first row of test into two columns
gather(key = "column_name", value = "value") %>%
# replace all values with ""
mutate(value = "") %>%
# reshape the data from long to wide
spread(column_name, value) %>%
# rearrange the column order to match that of test
select(colnames(data()))})
observeEvent( input$add, {
proxy5 %>%
addRow(user_table())
})
}
shinyApp(ui= ui, server = server)