Title: | Workflows for Building Web Applications |
---|---|
Description: | Sharing statistical methods or simulation frameworks through 'shiny' applications often requires workflows for handling data. To help save and display simulation results, the postgresUI() and postgresServer() functions in 'mmints' help with persistent data storage using a 'PostgreSQL' database. The 'mmints' package also offers data upload functionality through the csvUploadUI() and csvUploadServer() functions which allow users to upload data, view variables and their types, and edit variable types before fitting statistical models within the 'shiny' application. These tools aim to enhance efficiency and user interaction in 'shiny' based statistical and simulation applications. |
Authors: | Mackson Ncube [aut, cre], mightymetrika, LLC [cph, fnd] |
Maintainer: | Mackson Ncube <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.0.9000 |
Built: | 2025-02-18 17:26:42 UTC |
Source: | https://github.com/mightymetrika/mmints |
This function sets up the server-side logic for the Authentication module, handling user authentication, signup, and guest access.
authServer(id, postgres_module, user_table = "users")
authServer(id, postgres_module, user_table = "users")
id |
A character string that matches the ID used in |
postgres_module |
A postgresModule instance to handle database operations |
user_table |
A character string specifying the name of the users table |
A list containing authentication status and user information
server <- function(input, output, session) { postgres <- postgresServer("postgres_module", ...) auth <- authServer("auth_module", postgres, "users") }
server <- function(input, output, session) { postgres <- postgresServer("postgres_module", ...) auth <- authServer("auth_module", postgres, "users") }
This function generates the UI components for the Authentication module, including login, signup, and guest access options.
authUI(id)
authUI(id)
id |
A character string that uniquely identifies this module instance |
A list containing UI elements for authentication
shiny::fluidPage( authUI("auth_module") )
shiny::fluidPage( authUI("auth_module") )
This function defines the server logic for the citation module.
citationServer(id, citations)
citationServer(id, citations)
id |
A character string that matches the ID used in |
citations |
A named list of citations. Each element can be:
|
A Shiny module server function.
citations <- list( "Example Citation" = "Author, A. (Year). Title. Journal, Vol(Issue), pages.", "R Citation" = function() format_citation(utils::citation()) ) server <- function(input, output, session) { citationServer("my_citations", citations) }
citations <- list( "Example Citation" = "Author, A. (Year). Title. Journal, Vol(Issue), pages.", "R Citation" = function() format_citation(utils::citation()) ) server <- function(input, output, session) { citationServer("my_citations", citations) }
This function creates the UI elements for the citation module.
citationUI(id)
citationUI(id)
id |
A character string that defines the namespace for the module. |
A list containing two elements:
button
: An action button to show citations.
output
: A tag list containing the citation header and output.
citationUI("my_citations")
citationUI("my_citations")
This function defines the server logic for the CSV upload module.
csvUploadServer(id, vars_title = "Available Variables")
csvUploadServer(id, vars_title = "Available Variables")
id |
A character string that matches the ID used in |
vars_title |
A character string for the title of the variables table. |
A reactive expression containing the uploaded data.
server <- function(input, output, session) { csvUploadServer("my_data", "My Variables") }
server <- function(input, output, session) { csvUploadServer("my_data", "My Variables") }
This function creates the UI elements for the CSV upload module.
csvUploadUI(id)
csvUploadUI(id)
id |
A character string that defines the namespace for the module. |
A list containing two elements:
input
: The file input UI for uploading a CSV file.
output
: The UI for displaying the variables table.
csvUploadUI("my_data")
csvUploadUI("my_data")
This function formats a citation object into a format ready for use in 'shiny' applications
format_citation(cit)
format_citation(cit)
cit |
A citation object obtained from |
A character string containing the formatted citation.
format_citation(utils::citation("base"))
format_citation(utils::citation("base"))
This function generates a unique run code for use in Shiny applications, particularly those running simulations. The code combines a timestamp with a random string to ensure uniqueness for each row or run.
generateRunCode(time_format = "%Y%m%d%H%M%S", string_length = 5)
generateRunCode(time_format = "%Y%m%d%H%M%S", string_length = 5)
time_format |
A string specifying the format for the timestamp. Default is "%Y%m%d%H%M%S" (year, month, day, hour, minute, second). |
string_length |
An integer specifying the length of the random string. Default is 5. |
A character string containing the unique run code, composed of a timestamp and a random alphanumeric string, separated by an underscore.
This function uses the current system time and a random string to generate the run code. While collisions are extremely unlikely, they are theoretically possible, especially if the function is called multiple times within the same second and with a short string_length.
generateRunCode() generateRunCode(time_format = "%Y%m%d", string_length = 8)
generateRunCode() generateRunCode(time_format = "%Y%m%d", string_length = 8)
Handle Null Values for Text to List Conversions
list_null(par_input = "", alt_na = NULL)
list_null(par_input = "", alt_na = NULL)
par_input |
A string input, default is "". |
alt_na |
If alt_na is not set to NULL (the default), then it is an alternative string used to represent NA. Usually, this is a string such as "NA", "NaN", etc |
NULL if input is NA, if input is empty, or if input is alt_na (and alt_na is not NULL). Otherwise return a parsed list.
# Convert missing value to null list_null() list_null(NA) list_null("na", alt_na="na") # Convert non-missing value to list list_null("'one' = 1, 'two' = 2, 'three' = 3") # Convert to null when a single vector is missing list_null("'one' = 1, 'two' = NA, 'three' = 3", alt_na = "NA") list_null("'one' = 1, NA, 'three' = 3", alt_na = "NA")
# Convert missing value to null list_null() list_null(NA) list_null("na", alt_na="na") # Convert non-missing value to list list_null("'one' = 1, 'two' = 2, 'three' = 3") # Convert to null when a single vector is missing list_null("'one' = 1, 'two' = NA, 'three' = 3", alt_na = "NA") list_null("'one' = 1, NA, 'three' = 3", alt_na = "NA")
This function sets up the server-side logic for the Postgres Shiny module, handling database connections, data submission, retrieval, and download.
postgresServer(id, dbname, datatable, host, port, user, password, data)
postgresServer(id, dbname, datatable, host, port, user, password, data)
id |
A character string that matches the ID used in |
dbname |
A character string specifying the name of the database |
datatable |
A character string specifying the name of the table in the database |
host |
A character string specifying the host of the database |
port |
A numeric value specifying the port number for the database connection |
user |
A character string specifying the username for database access |
password |
A character string specifying the password for database access |
data |
A reactive expression that provides the data to be submitted |
A list of functions and reactive values:
executeQuery |
A function to run arbitrary SQL |
saveData |
A function to save data to the database |
loadData |
A function to load data from the database |
current_data |
A reactive value containing the current data in the table |
data_to_submit |
A reactive value containing the data to be submitted |
server <- function(input, output, session) { postgres_module <- postgresServer("postgres_module", "my_db", "my_table", "localhost", 5432, "user", "password", reactive({ input$data })) }
server <- function(input, output, session) { postgres_module <- postgresServer("postgres_module", "my_db", "my_table", "localhost", 5432, "user", "password", reactive({ input$data })) }
This function generates the UI components for the Postgres Shiny module, including a submit button, a data table, and a download button.
postgresUI(id)
postgresUI(id)
id |
A character string that uniquely identifies this module instance |
A list containing three UI elements:
submit |
An action button for submitting data to database |
table |
A DT output for displaying the database data |
download |
A download button for exporting database data to csv |
shiny::fluidPage( postgresUI("postgres_module")$submit, postgresUI("postgres_module")$table, postgresUI("postgres_module")$download )
shiny::fluidPage( postgresUI("postgres_module")$submit, postgresUI("postgres_module")$table, postgresUI("postgres_module")$download )
Convert Text Input to List
text_to_list(text_input)
text_to_list(text_input)
text_input |
A text representation of a list. |
A list parsed from the input string.
# Create a named list text_to_list("'one' = 1, 'two' = 2, 'three' = 3") # Create a list of vectors text_to_list("c('x1', 'x2'), c('x3', 'x4')")
# Create a named list text_to_list("'one' = 1, 'two' = 2, 'three' = 3") # Create a list of vectors text_to_list("c('x1', 'x2'), c('x3', 'x4')")
The goal of this function is to take text input and convert it to an R vector.
text_to_vector(text_input)
text_to_vector(text_input)
text_input |
A string input to be converted to a vector. |
A vector parsed from the input string.
text_to_vector("1,2,3,4,5") text_to_vector("1:5") text_to_vector("rep(1:5, times = 2)") text_to_vector("seq(1,10,2)")
text_to_vector("1,2,3,4,5") text_to_vector("1:5") text_to_vector("rep(1:5, times = 2)") text_to_vector("seq(1,10,2)")
Handle Null Values for Text to Vector Conversion
vec_null(par_input = "", alt_na = NULL)
vec_null(par_input = "", alt_na = NULL)
par_input |
A string input, default is "". |
alt_na |
If alt_na is not set to NULL (the default), then it is an alternative string used to represent NA. Usually, this is a string such as "NA", "NaN", etc. |
NULL if input is NA, if input is empty, or if input is alt_na (and alt_na is not NULL). Otherwise, return a vector.
# Convert missing value to NULL vec_null() vec_null(NA) vec_null("na", alt_na="na") # Convert string to vector when input is not missing num_vec <- vec_null("2,8,3,7") # Convert string to NULL when a single element is missing vec_null("2,3,NA,5", "NA")
# Convert missing value to NULL vec_null() vec_null(NA) vec_null("na", alt_na="na") # Convert string to vector when input is not missing num_vec <- vec_null("2,8,3,7") # Convert string to NULL when a single element is missing vec_null("2,3,NA,5", "NA")