I am working on this code where I am trying to make a new row and my existing rows has this actionbutton "Reward", after I try to insert a new row the actionbutton does not show up on the new row, is there a way I can add the actionbutton to the new row?
Also after adding a new row "1" shows up where Names would be, is there a way to get rid of that 1?
Thank you in advance! Any help is greatly appreciated.
library(shiny)
library(DT)
library(tidyverse)
dFramex <- data.frame(Name = c('Dilbert', 'Alice', 'Wally', 'Ashok', 'Dogbert'),
Motivation = c(62, 73, 3, 99, 52))
ui <- fluidPage(
fluidRow(
actionButton("save","Add Data"),
DT::dataTableOutput(outputId = "table")
)
)
server <- function(input, output, session) {
shinyInput <- function(FUN, len, id, ...) {
inputs <- character(len)
for (i in seq_len(len)) {
inputs[i] <- as.character(FUN(paste0(id, i), ...))
}
inputs
}
user_table <-
dFramex %>%
slice(1) %>%
replace(values = "")
df <- reactiveValues(data = data.frame(
dFramex,
Actions = shinyInput(actionButton, nrow(dFramex),
'button_', label = "Reward", onclick = 'Shiny.onInputChange(\"select_button\", this.id)' ),
stringsAsFactors = FALSE
))
output$table <-
DT::renderDataTable({DT::datatable({ df$data
},options = list(searching = FALSE, selection= FALSE)
,editable = TRUE,
escape = FALSE,
rownames = FALSE
)
}, server = FALSE)
proxy <- dataTableProxy(outputId = "table")
observeEvent(eventExpr = input$save, {
proxy %>%
addRow(user_table)
})
}
shinyApp(ui, server)