Select, rename and convert variables
Usage
update_variables_ui(id, title = TRUE)
update_variables_server(
id,
data,
height = NULL,
return_data_on_init = FALSE,
try_silent = FALSE
)
Arguments
- id
Module's ID
- title
Module's title, if
TRUE
use the default title, useNULL
for no title or ashiny.tag
for a custom one.- data
a
data.frame
or areactive
function returning adata.frame
.- height
Height for the table.
- return_data_on_init
Return initial data when module is called.
- try_silent
logical: should the report of error messages be suppressed?
Value
A shiny::reactive()
function returning the updated data.
Examples
library(shiny)
library(datamods)
testdata <- data.frame(
date_as_char = as.character(Sys.Date() + 0:9),
date_as_num = as.numeric(Sys.Date() + 0:9),
datetime_as_char = as.character(Sys.time() + 0:9 * 3600*24),
datetime_as_num = as.numeric(Sys.time() + 0:9 * 3600*24),
num_as_char = as.character(1:10),
char = month.name[1:10],
char_na = c("A", "A", "B", NA, "B", "A", NA, "B", "A", "B"),
stringsAsFactors = FALSE
)
ui <- fluidPage(
theme = bslib::bs_theme(version = 5L, preset = "bootstrap"),
tags$h3("Select, rename and convert variables"),
fluidRow(
column(
width = 6,
# radioButtons()
update_variables_ui("vars")
),
column(
width = 6,
tags$b("original data:"),
verbatimTextOutput("original"),
verbatimTextOutput("original_str"),
tags$b("Modified data:"),
verbatimTextOutput("modified"),
verbatimTextOutput("modified_str")
)
)
)
#> Warning: i18n: translation for 'Select, rename and convert variables in table above, then apply changes by clicking button below.' not found!
server <- function(input, output, session) {
updated_data <- update_variables_server(
id = "vars",
data = reactive(testdata),
return_data_on_init = FALSE
)
output$original <- renderPrint({
testdata
})
output$original_str <- renderPrint({
str(testdata)
})
output$modified <- renderPrint({
updated_data()
})
output$modified_str <- renderPrint({
str(updated_data())
})
}
if (interactive())
shinyApp(ui, server)