I\'m trying to create a DT with several inputs in Shiny. The columns with selectInput and numericInput work fine, but the one with dateInputs doesn\'t. It\'s like the input$
library(shiny)
library(DT)
ui <- fluidPage(
# define a hidden dateInput in order that Shiny loads the dependencies
div(style = "display: none;",
dateInput("x", label = NULL)
),
DTOutput("table")
)
js <- c(
"function(settings){",
" $('#calendar').bsDatepicker({",
" format: 'yyyy-mm-dd',",
" todayHighlight: true",
" });",
"}"
) # available options: https://bootstrap-datepicker.readthedocs.io/en/latest/
server <- function(input, output, session){
output[["table"]] <- renderDT({
dat <- data.frame(
V1 = "A",
V2 = 99,
V3 = '<input id="calendar" type="text" class="form-control" value = "2019-03-08"/>',
stringsAsFactors = FALSE
)
datatable(dat, escape = FALSE,
options =
list(
initComplete = JS(js),
preDrawCallback = JS('function() { Shiny.unbindAll(this.api().table().node()); }'),
drawCallback = JS('function() { Shiny.bindAll(this.api().table().node()); } ')
)
)
})
}
shinyApp(ui, server)
html <- '
<div class="input-daterange input-group" id="calendar">
<input type="text" class="input-sm form-control" name="start" value = "2019-03-08" />
<span class="input-group-addon">to</span>
<input type="text" class="input-sm form-control" name="end" value = "2019-03-12" />
</div>'
output[["table"]] <- renderDT({
dat <- data.frame(
V1 = "A",
V2 = 99,
V3 = html,
stringsAsFactors = FALSE
)
datatable(dat, escape = FALSE,
options =
list(
initComplete = JS(js),
preDrawCallback = JS('function() { Shiny.unbindAll(this.api().table().node()); }'),
drawCallback = JS('function() { Shiny.bindAll(this.api().table().node()); } ')
)
)
})