Package 'sap'

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

Help Index


Shiny app display mode helper

Description

Shiny app display mode helper

Usage

display_type(run = "w")

Arguments

run

where to launch app:

  • "p" = launch in viewer pane

  • "b" = launch in external browser

  • "w" = launch in window (default)

Value

notification of shinyViewerType option


Launch the Movies Review Application

Description

Starts the Movies Review Shiny application, which provides a customizable scatter plot interface for analyzing movie data.

Usage

launch_app(app = NULL, options = list(), mode = "run", run = "p", ...)

Arguments

app

which app to run. Options are:

  • NULL = the default app ("movies")

  • "bslib" = alternative bslib layout

  • "ggp2" = ggplot2movies (tidy) data app.

  • "quarto" = Quarto movies app.

options

arguments to pass to options()

mode

launch mode. Choices are:

  • run = blocking, uses display_type() for window placement (default)

  • start = non-blocking, launches in a background process

run

where to launch app:

  • p = launch in viewer pane

  • b = launch in external browser

  • w = launch in window

...

arguments passed to UI

Details

See the ggplot2movies package.

Value

A Shiny application object.

Details

The application uses:

See Also

Examples

if (interactive()) {
  launch_app()
}

Log Application Behaviors

Description

A simple logging function for logging Shiny events and behaviors.

Usage

log_message(message, log_file = "logs/app_log.txt", save = FALSE)

Arguments

message

log message

log_file

name of log file (defaults to "app_log.txt")

save

print or save log file

Value

A log message to the console and the log_file.

See Also

Other Utility Functions: scatter_plot()

Examples

if (interactive()) {
  log_message("message")
}

Log Messages to Console and File with Optional JSON Format

Description

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.

Usage

logr_msg(
  message,
  level = "INFO",
  log_file = "app_log.txt",
  json = FALSE,
  store_log = FALSE
)

Arguments

message

A character string representing the message to be logged.

level

A character string indicating the log level. One of:

  • "FATAL"

  • "ERROR"

  • "WARN"

  • "SUCCESS"

  • "INFO" (default)

  • "DEBUG"

  • "TRACE"

log_file

A character string specifying the path to the log file. Ignored if store_log = FALSE. Defaults to "app_log.txt".

json

A logical value indicating whether to save logs in JSON format. Defaults to FALSE. When TRUE, logs are written to log_file as JSON objects.

store_log

A logical value indicating whether logs should be saved to a file. Defaults to TRUE:

  • If TRUE, logs are printed to the console and stored in log_file

  • If FALSE, logs are printed to the console

Details

  • 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.

Value

The function is called for its side effects of logging messages and does not return a value.

See Also

Examples

# 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)

Aesthetics Input Module - Server

Description

Handles the server-side logic for the variable input module.

Usage

mod_aes_input_server(id)

Arguments

id

(character) Namespace ID for the module.

Value

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.

Details

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.

See Also


Aesthetics Input Module - UI

Description

Creates a UI for selecting attributes for a scatter plot.

Usage

mod_aes_input_ui(id)

Arguments

id

(character) Namespace ID for the module.

Value

A shiny::tagList() containing UI elements for variable selection.

Details

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.

See Also

Examples

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())
      )
    }
  )
}

Scatter Plot Display Module - Server

Description

Handles the server-side logic for rendering a scatter plot.

Usage

mod_scatter_display_server(id, var_inputs, aes_inputs)

Arguments

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.

Value

No direct return value. This function generates a plot output.

Details

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.

Reactive Inputs

  • 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.

See Also

Other Plot Display Module: mod_scatter_display_ui()

Examples

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)
    }
  )
}

Scatter Plot Display Module - UI

Description

Creates a UI for displaying a scatter plot with user-selected options.

Usage

mod_scatter_display_ui(id)

Arguments

id

(character) Namespace ID for the module.

Value

A shiny::tagList containing the plot output and metadata.

Details

mod_scatter_display_ui() includes:

  • A scatter plot created dynamically based on user input.

  • Metadata about the app, including the data source.

See Also

Other Plot Display Module: mod_scatter_display_server()

Examples

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.
    }
  )
}

Variable Input Module - Server

Description

Handles the server-side logic for the variable input module.

Usage

mod_var_input_server(id)

Arguments

id

(character) Namespace ID for the module.

Value

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.

Details

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.

See Also

Other Variable Input Module: mod_var_input_ui()

Examples

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()))
    }
  )
}

Variable Input Module - UI

Description

Creates a UI for selecting variables for a scatter plot.

Usage

mod_var_input_ui(id)

Arguments

id

(character) Namespace ID for the module.

Value

A shiny::tagList() containing UI elements for variable selection.

Details

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.

See Also

Other Variable Input Module: mod_var_input_server()

Examples

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())
      )
    }
  )
}

IMDB movies data

Description

Movie review data. Note: these data come from the Building Web Applications with shiny course.

Usage

movies

Format

A data frame with 651 rows and 34 variables:

title

movie title

title_type

type, fct (Documentary, Feature Film, TV Movie)

genre

movie genre, fct (Action & Adventure, Animation, etc.

runtime

movie length in minutes, num, avg = 106, sd = 19.4

mpaa_rating

movie rating, fct (G, NC-17, PG, PG-13, R, Unrated)

studio

name of studio, chr

thtr_rel_date

Theatre release date, POSIXct, min = 1970-05-19 21:00:00, max = 2014-12-24 21:00:00

thtr_rel_year

Theatre release year, num, min = 1970, max = 2014

thtr_rel_month

Theatre release month, num, min = 1, max =12

thtr_rel_day

Theatre release day, num, min = 1, max =31

dvd_rel_date

DVD release date, POSIXct, min = 1991-03-27 21:00:00, max = 2015-03-02 21:00:00

dvd_rel_year

DVD release year, num, min = 1991, max = 2015

dvd_rel_month

DVD release month, num, min = 1, max = 12

dvd_rel_day

DVD release day, num, min = 1, max = 31

imdb_rating

Internet movie database rating, avg = 6.49, sd = 1.08

imdb_num_votes

Internet movie database votes, avg = 57533, sd = 112124

critics_rating

Rotten tomatoes rating, fct (Certified Fresh, Fresh, Rotten)

critics_score

Rotten tomatoes score, avg = 57.7, sd = 28.4

audience_rating

Audience rating, fct (Spilled, Upright)

audience_score

Audience score, avg = 62.4, sd = 20.2

best_pic_nom

Best picture nomination, fct (no, yes)

best_pic_win

Best picture win, fct (no, yes)

best_actor_win

Best actor win, fct (no, yes)

best_actress_win

Best actress win, fct (no, yes)

best_dir_win

Best director win, fct (no, yes)

top200_box

Top 20 box-office, fct (no, yes)

director

Name of director, chr

actor1

Name of leading actor, chr

actor2

Name of supporting actor, chr

actor3

Name of #3 actor, chr

actor4

Name of #4 actor, chr

actor5

Name of #5 actor, chr

imdb_url

IMDB URL

rt_url

Rotten tomatoes URL

Details

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.

Description

Handles the server-side logic for the Movies Review application.

Usage

movies_server(input, output, session)

Arguments

input

The Shiny input object.

output

The Shiny output object.

session

The Shiny session object.

Value

Defines server logic for reactive outputs and module integration.

Details

The server integrates the following modules:

See Also

Other Application Components: movies_ui()

Examples

if (interactive()) {
  shiny::shinyApp(ui = movies_ui(), server = movies_server)
}

User Interface for the Movies Review Application

Description

Creates the user interface (UI) for the Movies Review application, which allows users to create customizable scatter plots based on movie data.

Usage

movies_ui(bslib = FALSE)

Arguments

bslib

View bslib logo?

Value

A Shiny tagList object containing the UI elements.

Details

The interface is built using bslib

See Also

Other Application Components: movies_server()

Examples

if (interactive()) {
  shiny::shinyApp(ui = movies_ui(), server = movies_server)
}

Generate a Scatter Plot

Description

Creates a scatter plot using ggplot2 with the specified data and aesthetics.

Usage

scatter_plot(df, x_var, y_var, col_var, alpha_var, size_var)

Arguments

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.

Value

A ggplot object representing the scatter plot.

Details

scatter_plot() is designed for use in Shiny applications but can also be used independently. It supports customization of transparency, size, and color aesthetics.

See Also

Other Utility Functions: log_message()

Examples

scatter_plot(
  df = mtcars,
  x_var = "mpg",
  y_var = "hp",
  col_var = "cyl",
  alpha_var = 0.7,
  size_var = 3
)