Reputation: 73
I'm trying to get the placeholder or cell name for a specific column in editable datatable in shiny R. This would ensure user aware that a specific column can be edit.
I provide some example of code. Instead of column count show value 0, I want a placeholder/cell label would appear like "double click here to input value". I don't want to store iris$count <- "double click to input"
ui <- fluidPage(
DT::dataTableOutput("table"),
)
server <- shinyServer (
function (input, output, session) {
observeEvent(input$table3_cell_edit,{
info = input$table3_cell_edit
str(info)
i = info$row
j = info$col
v = info$value
vals$df_input <<- editData(vals$df_input, info)
})
output$table <- DT::renderDataTable (iris,
editable = list(target = 'cell', disable = list( columns = c(1,2,3,4,5)) ))
}
)
shinyApp(ui = ui, server = server)
This is what current code produce
What i want something like this
Thank you in advance.
Upvotes: 0
Views: 370
Reputation: 73
library(shiny)
library(DT)
CSS <- "
table td.withPlaceholder:empty:before {
content: 'Double click here to input value';
color: gray;
}
"
iris$count <- ""
ui <- fluidPage(
tags$head(
tags$style(HTML(CSS))
),
DT::dataTableOutput("table"),
)
server <- shinyServer (
function (input, output, session) {
observeEvent(input$table3_cell_edit,{
info = input$table3_cell_edit
str(info)
i = info$row
j = info$col
v = info$value
vals$df_input <<- editData(vals$df_input, info)
})
output$table <- DT::renderDataTable (iris,
editable = list(target = 'cell', disable = list( columns = c(1,2,3,4,5)) ),
options = list( columnDefs = list(list(targets = 6, className = "withPlaceholder")))
)
}
)
shinyApp(ui = ui, server = server)
Upvotes: 0