register_dt registers a DT datatable for linking with other components.
Usage
register_dt(
session,
registry,
dt_output_id,
data_reactive,
shared_id_column,
click_handler = NULL
)Arguments
- session
'shiny' session object. The session from the module where the DT is used. This could be global session in non-modular apps.
- registry
A link registry created by
create_link_registry()- dt_output_id
Character string: the outputId of your DT::DTOutput
- data_reactive
Reactive expression returning the data frame for the table
Character string: name of the ID column
- click_handler
Optional function: custom click handler for row selection, must have args (map_proxy, selected_data, session), overrides all default behavior
Examples
# \donttest{
# Create a mock session for the example
session <- shiny::MockShinySession$new()
# Create a registry
registry <- create_link_registry(session)
# Sample reactive data
my_data <- shiny::reactive({
data.frame(
id = 1:5,
name = c("A", "B", "C", "D", "E"),
value = 11:15
)
})
# Register a DT component
register_dt(session, registry, "my_table", my_data, "id")
# Verify registration
print(registry$get_components())
#> $`mock-session-my_table`
#> $`mock-session-my_table`$type
#> [1] "datatable"
#>
#> $`mock-session-my_table`$shared_id_column
#> [1] "id"
#>
#> $`mock-session-my_table`$config
#> $`mock-session-my_table`$config$click_handler
#> NULL
#>
#>
#>
# }