I created an app with shiny and shinyTable. It reads a csv file as data.frame and saves changes or new rows.
If I add a new row, it is saved but not shown in the table. I can only see the row in the table when I restart the app. How can I make sure that the submit button adds the row without restarting the app?
EDIT: I can generate this functionality with shiny and a "normal" table with renderTable
, but I can't manage to get this working with shinyTable.
What I basically want to achieve is this functionality with shinyTable to have an editable table where I can add rows.
app.R
require(shiny)
datafile<-read.csv("data.csv", header=TRUE, sep=",", quote="")
runApp(
list(
ui = fluidPage(
headerPanel('Title'),
sidebarPanel(
textInput("fielda", label="fielda", value=""),
textInput("fieldb", label="fieldb", value=""),
actionButton("addButton", "insert data")
),
mainPanel(
tableOutput("table"))
),
server = function(input, output) {
datafile_sample <- datafile[sample(nrow(datafile)),]
row.names(datafile_sample) <- NULL
values <- reactiveValues()
values$df <- datafile_sample
addData <- observe({
if(input$addButton > 0) {
newLine <- isolate(c(input$fielda, input$fieldb))
isolate(values$df <- rbind(as.matrix(values$df), unlist(newLine)))
write.csv(values$df, file = "data.csv", row.names=F, quote=F)
}
})
output$table <- renderTable({values$df}, include.rownames=F)
}
)
)
data.csv
fielda,fieldb
1,2
3,4