| Title: | Shiny App-Packages |
|---|---|
| Description: | An R package with a collection of Shiny applications. |
| Authors: | John Smith <[email protected]> [aut, cre] |
| Maintainer: | John Smith <[email protected]> |
| License: | GPL-3 |
| Version: | 0.0.0.9200 |
| Built: | 2026-10-30 21:02:38 UTC |
| Source: | https://github.com/mjfrigaard/sap |
Shiny app display mode helper
display_type(run = "w")display_type(run = "w")
run |
where to launch app:
|
notification of shinyViewerType option
Starts the Movies Review Shiny application, which provides a customizable scatter plot interface for analyzing movie data.
launch_app(app = NULL, options = list(), mode = "run", run = "p", ...)launch_app(app = NULL, options = list(), mode = "run", run = "p", ...)
app |
which app to run. Options are:
|
options |
arguments to pass to |
mode |
launch mode. Choices are:
|
run |
where to launch app:
|
... |
arguments passed to UI |
See the ggplot2movies package.
A Shiny application object.
The application uses:
UI: Defined in movies_ui().
Server Logic: Defined in movies_server().
movies_ui() for the user interface.
movies_server() for the server logic.
if (interactive()) { launch_app() }if (interactive()) { launch_app() }
A simple logging function for logging Shiny events and behaviors.
log_message(message, log_file = "logs/app_log.txt", save = FALSE)log_message(message, log_file = "logs/app_log.txt", save = FALSE)
message |
log message |
log_file |
name of log file (defaults to "app_log.txt") |
save |
print or save log file |
A log message to the console and the log_file.
Other Utility Functions:
scatter_plot()
if (interactive()) { log_message("message") }if (interactive()) { log_message("message") }
A utility function for logging messages to the console and optionally to a log file. Messages can be stored as plain text (default) or in JSON format. Additionally, logging to a file can be disabled altogether.
logr_msg( message, level = "INFO", log_file = "app_log.txt", json = FALSE, store_log = FALSE )logr_msg( message, level = "INFO", log_file = "app_log.txt", json = FALSE, store_log = FALSE )
message |
A character string representing the message to be logged. |
level |
A character string indicating the log level. One of:
|
log_file |
A character string specifying the path to the log file.
Ignored if |
json |
A logical value indicating whether to save logs in JSON format.
Defaults to |
store_log |
A logical value indicating whether logs should be saved
to a file. Defaults to
|
Console Logging: All messages are always logged to the console.
File Logging: If store_log = TRUE and log_file is specified,
messages are logged to the file in either plain text or JSON format.
JSON Logs: When json = TRUE, log messages are stored as structured
JSON objects with the fields:
timestamp: The time the message was logged.
level: The severity level of the log.
message: The actual log message.
The function is called for its side effects of logging messages and does not return a value.
logger::log_appender() for configuring log destinations.
logger::log_formatter() for customizing log message formats.
jsonlite::toJSON() for converting R objects to JSON.
# Log a simple informational message to the console logr_msg("Application started.") # Log an error message to the console and a file logr_msg("Failed to connect to database.", level = "ERROR", log_file = "error_log.txt") # Log a success message in JSON format logr_msg("User login successful.", level = "SUCCESS", log_file = "app_log.json", json = TRUE) # Log a warning message to the console only (no file storage) logr_msg("Low memory warning.", level = "WARN", store_log = FALSE)# Log a simple informational message to the console logr_msg("Application started.") # Log an error message to the console and a file logr_msg("Failed to connect to database.", level = "ERROR", log_file = "error_log.txt") # Log a success message in JSON format logr_msg("User login successful.", level = "SUCCESS", log_file = "app_log.json", json = TRUE) # Log a warning message to the console only (no file storage) logr_msg("Low memory warning.", level = "WARN", store_log = FALSE)
Handles the server-side logic for the variable input module.
mod_aes_input_server(id)mod_aes_input_server(id)
id |
(character) Namespace ID for the module. |
A reactive expression that returns a list of selected input values:
alpha: Transparency level of points (0-1).
size: Size of the points.
plot_title: Title for the scatter plot.
mod_aes_input_server() reads user input from the corresponding UI
function created with mod_aes_input_ui(). It processes and returns a reactive object
containing the selected plot attributes.
mod_aes_input_ui() for the UI counterpart of this module.
mod_scatter_display_server() for displaying the scatter plot.
Creates a UI for selecting attributes for a scatter plot.
mod_aes_input_ui(id)mod_aes_input_ui(id)
id |
(character) Namespace ID for the module. |
A shiny::tagList() containing UI elements for variable
selection.
mod_aes_input_ui() provides UI controls for customizing scatter plots.
It includes:
Sliders:
Transparency (alpha) ranging from 0 to 1.
Point size ranging from 0 to 5.
Text Input:
Plot title.
The function uses shiny::NS() to namespace all input IDs.
mod_aes_input_server() for server-side logic.
shiny::tagList()
for containing UI elements.
shiny::NS()
for namespacing.
if (interactive()) { shiny::shinyApp( ui = shiny::fluidPage(mod_aes_input_ui("aes")), server = function(input, output, session) { selected_vars <- mod_aes_input_server("aes") shiny::observe( print(selected_vars()) ) } ) }if (interactive()) { shiny::shinyApp( ui = shiny::fluidPage(mod_aes_input_ui("aes")), server = function(input, output, session) { selected_vars <- mod_aes_input_server("aes") shiny::observe( print(selected_vars()) ) } ) }
Handles the server-side logic for rendering a scatter plot.
mod_scatter_display_server(id, var_inputs, aes_inputs)mod_scatter_display_server(id, var_inputs, aes_inputs)
id |
(character) Namespace ID for the module. |
var_inputs |
(reactive) A reactive expression containing user-selected variables. |
aes_inputs |
(reactive) A reactive expression containing user-selected attributes. |
No direct return value. This function generates a plot output.
mod_scatter_display_server():
Uses var_inputs to dynamically generate a scatter plot with
user-selected variables.
Reads from the movies dataset, which must be loaded in the app
environment.
Processes plot titles and axis labels to improve readability.
var_inputs()$x: X-axis variable.
var_inputs()$y: Y-axis variable.
var_inputs()$z: Color aesthetic variable.
aes_inputs()$alpha: Transparency level.
aes_inputs()$size: Size of points.
aes_inputs()$plot_title: Title of the plot.
mod_var_input_server() for variable selection.
mod_aes_input_server() for aesthetics selection.
scatter_plot() for generating the scatter plot.
Other Plot Display Module:
mod_scatter_display_ui()
if (interactive()) { shiny::shinyApp( ui = shiny::fluidPage( mod_var_input_ui("vars"), mod_aes_input_ui("aes"), mod_scatter_display_ui("plot") ), server = function(input, output, session) { selected_vars <- mod_var_input_server("vars") selected_aes <- mod_var_input_server("aes") mod_scatter_display_server("plot", selected_vars, selected_aes) } ) }if (interactive()) { shiny::shinyApp( ui = shiny::fluidPage( mod_var_input_ui("vars"), mod_aes_input_ui("aes"), mod_scatter_display_ui("plot") ), server = function(input, output, session) { selected_vars <- mod_var_input_server("vars") selected_aes <- mod_var_input_server("aes") mod_scatter_display_server("plot", selected_vars, selected_aes) } ) }
Creates a UI for displaying a scatter plot with user-selected options.
mod_scatter_display_ui(id)mod_scatter_display_ui(id)
id |
(character) Namespace ID for the module. |
A shiny::tagList containing the plot output and metadata.
mod_scatter_display_ui() includes:
A scatter plot created dynamically based on user input.
Metadata about the app, including the data source.
mod_scatter_display_server() for the server-side logic of this
module.
scatter_plot() for the utility function generating the plot.
Other Plot Display Module:
mod_scatter_display_server()
if (interactive()) { shiny::shinyApp( ui = shiny::fluidPage(mod_scatter_display_ui("plot")), server = function(input, output, session) { # Example usage - server logic is minimal for standalone testing. } ) }if (interactive()) { shiny::shinyApp( ui = shiny::fluidPage(mod_scatter_display_ui("plot")), server = function(input, output, session) { # Example usage - server logic is minimal for standalone testing. } ) }
Handles the server-side logic for the variable input module.
mod_var_input_server(id)mod_var_input_server(id)
id |
(character) Namespace ID for the module. |
A reactive expression that returns a list of selected input values:
y: Variable for the y-axis.
x: Variable for the x-axis.
z: Variable for the point colors.
mod_var_input_server() reads user input from the corresponding UI
function created with mod_var_input_ui(). It processes and returns
a reactive object containing the selected variables.
mod_var_input_ui() for the UI counterpart of this module.
mod_scatter_display_server() for displaying the scatter plot.
Other Variable Input Module:
mod_var_input_ui()
if (interactive()) { shiny::shinyApp( ui = shiny::fluidPage(mod_var_input_ui("vars")), server = function(input, output, session) { selected_vars <- mod_var_input_server("vars") shiny::observe(print(selected_vars())) } ) }if (interactive()) { shiny::shinyApp( ui = shiny::fluidPage(mod_var_input_ui("vars")), server = function(input, output, session) { selected_vars <- mod_var_input_server("vars") shiny::observe(print(selected_vars())) } ) }
Creates a UI for selecting variables for a scatter plot.
mod_var_input_ui(id)mod_var_input_ui(id)
id |
(character) Namespace ID for the module. |
A shiny::tagList() containing UI elements for variable
selection.
mod_var_input_ui() provides UI controls for customizing scatter plots.
It includes:
Dropdowns:
X-axis variable
Y-axis variable
Color variable
The function uses shiny::NS() to namespace all input IDs.
mod_var_input_server() for server-side logic.
shiny::tagList()
for containing UI elements.
shiny::NS()
for namespacing.
Other Variable Input Module:
mod_var_input_server()
if (interactive()) { shiny::shinyApp( ui = shiny::fluidPage(mod_var_input_ui("vars")), server = function(input, output, session) { selected_vars <- mod_var_input_server("vars") shiny::observe( print(selected_vars()) ) } ) }if (interactive()) { shiny::shinyApp( ui = shiny::fluidPage(mod_var_input_ui("vars")), server = function(input, output, session) { selected_vars <- mod_var_input_server("vars") shiny::observe( print(selected_vars()) ) } ) }
Movie review data. Note: these data come from the Building Web Applications with shiny course.
moviesmovies
A data frame with 651 rows and 34 variables:
movie title
type, fct (Documentary, Feature Film, TV Movie)
movie genre, fct (Action & Adventure, Animation, etc.
movie length in minutes, num, avg = 106, sd = 19.4
movie rating, fct (G, NC-17, PG, PG-13, R, Unrated)
name of studio, chr
Theatre release date, POSIXct, min = 1970-05-19 21:00:00, max = 2014-12-24 21:00:00
Theatre release year, num, min = 1970, max = 2014
Theatre release month, num, min = 1, max =12
Theatre release day, num, min = 1, max =31
DVD release date, POSIXct, min = 1991-03-27 21:00:00, max = 2015-03-02 21:00:00
DVD release year, num, min = 1991, max = 2015
DVD release month, num, min = 1, max = 12
DVD release day, num, min = 1, max = 31
Internet movie database rating, avg = 6.49, sd = 1.08
Internet movie database votes, avg = 57533, sd = 112124
Rotten tomatoes rating, fct (Certified Fresh, Fresh, Rotten)
Rotten tomatoes score, avg = 57.7, sd = 28.4
Audience rating, fct (Spilled, Upright)
Audience score, avg = 62.4, sd = 20.2
Best picture nomination, fct (no, yes)
Best picture win, fct (no, yes)
Best actor win, fct (no, yes)
Best actress win, fct (no, yes)
Best director win, fct (no, yes)
Top 20 box-office, fct (no, yes)
Name of director, chr
Name of leading actor, chr
Name of supporting actor, chr
Name of #3 actor, chr
Name of #4 actor, chr
Name of #5 actor, chr
IMDB URL
Rotten tomatoes URL
Read more about acquiring these data in the 'Web Scraping and programming' section of Data science in a box
Handles the server-side logic for the Movies Review application.
movies_server(input, output, session)movies_server(input, output, session)
input |
The Shiny |
output |
The Shiny |
session |
The Shiny |
Defines server logic for reactive outputs and module integration.
The server integrates the following modules:
Variable Input Module: Processes user input for scatter plot
customization using mod_var_input_server().
Plot Display Module: Generates and displays a scatter plot
based on user inputs using mod_scatter_display_server().
movies_ui() for the corresponding user interface.
launch_app() for the entry point of the application.
Other Application Components:
movies_ui()
if (interactive()) { shiny::shinyApp(ui = movies_ui(), server = movies_server) }if (interactive()) { shiny::shinyApp(ui = movies_ui(), server = movies_server) }
Creates the user interface (UI) for the Movies Review application, which allows users to create customizable scatter plots based on movie data.
movies_ui(bslib = FALSE)movies_ui(bslib = FALSE)
bslib |
View bslib logo? |
A Shiny tagList object containing the UI elements.
The interface is built using bslib
Page (fillable): bslib::page_fillable()
displays the app title.
Sidebar: bslib::layout_sidebar()
includes a logo and the variable
selection module.
(mod_var_input_ui).
Card: bslib::card()
displays the scatter plot module
(mod_scatter_display_ui).
movies_server() for the server logic of the app.
mod_var_input_ui() and mod_scatter_display_ui() for the modules
included in the UI.
Other Application Components:
movies_server()
if (interactive()) { shiny::shinyApp(ui = movies_ui(), server = movies_server) }if (interactive()) { shiny::shinyApp(ui = movies_ui(), server = movies_server) }
Creates a scatter plot using ggplot2 with the specified data and
aesthetics.
scatter_plot(df, x_var, y_var, col_var, alpha_var, size_var)scatter_plot(df, x_var, y_var, col_var, alpha_var, size_var)
df |
(data.frame) The dataset containing the variables to plot. |
x_var |
(character) Name of the variable for the x-axis. |
y_var |
(character) Name of the variable for the y-axis. |
col_var |
(character) Name of the variable for the color aesthetic. |
alpha_var |
(numeric) Transparency level of points (0 to 1). |
size_var |
(numeric) Size of points. |
A ggplot object representing the scatter plot.
scatter_plot() is designed for use in Shiny applications but can also be
used independently.
It supports customization of transparency, size, and color aesthetics.
mod_scatter_display_server() for integrating this function into the
scatter plot module.
ggplot2::ggplot() for details on
ggplot2 usage.
Other Utility Functions:
log_message()
scatter_plot( df = mtcars, x_var = "mpg", y_var = "hp", col_var = "cyl", alpha_var = 0.7, size_var = 3 )scatter_plot( df = mtcars, x_var = "mpg", y_var = "hp", col_var = "cyl", alpha_var = 0.7, size_var = 3 )
text_logo() generates a text-based logo enclosed within HTML tags, allowing
for the specification of the heading size (h1 through h6). The logo features
a stylized representation of a face within arrows, using ASCII characters.
text_logo(size = "h3")text_logo(size = "h3")
size |
A character string specifying the heading size for the logo. Valid options include "h1", "h2", "h3", "h4", "h5", and "h6". Defaults to "h3". |
An HTML object containing the logo. This object can be directly used in R Markdown documents or Shiny applications to render the logo in a web page.
# Generate a logo with default size h3 text_logo() # Generate a logo with size h1 text_logo(size = "h1")# Generate a logo with default size h3 text_logo() # Generate a logo with size h1 text_logo(size = "h1")