Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R Package Prep #4

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
paths: ['r-package/**']
Comment on lines +3 to +6
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to do something similar in .github/workflows/release.yml to avoid running Python checks unless the python-package files change.

Although there it's slightly more complicated because that workflow relies on tag pushes for publishing. (Otherwise I would have done that now.)

pull_request:
branches: [main, master]
paths: ['r-package/**']

name: R-CMD-check.yaml

permissions: read-all

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
working-directory: r-package
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v2
with:
working-directory: r-package
upload-snapshots: true
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
21 changes: 14 additions & 7 deletions r-package/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
Package: shinymedia
Title: Multimedia Input/Output Controls for Shiny
Title: Multimedia Input/Output Controls for 'Shiny'
Version: 0.0.0.9000
Authors@R:
person("Joe", "Cheng", , "[email protected]", role = c("aut", "cre"))
Description: What the package does (one paragraph).
Authors@R: c(
person("Joe", "Cheng", , "[email protected]", role = c("aut", "cre")),
person("Posit Software, PBC", role = c("cph", "fnd"))
)
Description: Extends the 'Shiny' web framework with controls for
multimedia input/output. Includes a video input control and an audio
output.
License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
URL: https://github.com/posit-dev/shinymedia
BugReports: https://github.com/posit-dev/shinymedia/issues
Imports:
base64enc,
htmltools,
rlang,
shiny
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
7 changes: 1 addition & 6 deletions r-package/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

export(audio_spinner)
export(input_video_clip)
import(base64enc)
import(htmltools)
importFrom(htmltools,div)
importFrom(htmltools,htmlDependency)
importFrom(htmltools,tag)
importFrom(htmltools,tagList)
importFrom(htmltools,tags)
importFrom(base64enc,base64encode)
importFrom(shiny,icon)
88 changes: 54 additions & 34 deletions r-package/R/audio_spinner.R
Original file line number Diff line number Diff line change
@@ -1,46 +1,66 @@
#' Create an audio spinner
#'
#' @param src The source URL or URI for the audio file. This should be used for remote resources
#' or data URIs. If provided, this takes precedence over `con`.
#' @param con An optional connection object or file path for local audio files. This is ignored
#' if `src` is provided. Use this for reading local files securely.
#' @param rpm The speed of the spinner, in clockwise revolutions per minute. Default is 10 RPM.
#' Use 0 to disable rotation, or a negative value to rotate counter-clockwise.
#' @param gap The gap between the blades of the spinner, in radians. Default is pi/5, or 36°.
#' @param stroke The stroke thickness of the individual arcs that make up each blade of the spinner,
#' in pixels. Default is 2.5.
#' @param min_radius The radius of the spinner when there is only silence, in pixels. Default is 30.
#' @param radius_compression The raw `[-1, 1]` amplitude of the audio is compressed using
#' `x^radius_compression` to make the spinner more responsive to quiet sounds. Default is 0.8.
#' Set to 1.0 to disable compression. (Note that this only affects the visualization, not the audio playback.)
#' @param radius_overscan Use this parameter to set the maximum possible radius of the spinner,
#' relative to the width/height of the container. Default is 1.1, meaning the spinner radius
#' will be scaled such that at maximum amplitude, it will be 10% larger than the container
#' (the spinner blades will be clipped). Use larger values if you're expecting generally quiet audio.
#' @param steps The number of concentric arcs that make up each blade of the spinner, not including
#' the central circle. Default is 2.
#' @param blades The number of blades in the spinner. Default is 3. Set to 0 to use concentric circles
#' instead of blades.
#' @param src The source URL or URI for the audio file. This should be used for
#' remote resources or data URIs. If provided, this takes precedence over
#' `con`.
#' @param con An optional connection object or file path for local audio files.
#' This is ignored if `src` is provided. Use this for reading local files
#' securely.
#' @param rpm The speed of the spinner, in clockwise revolutions per minute.
#' Default is 10 RPM. Use 0 to disable rotation, or a negative value to rotate
#' counter-clockwise.
#' @param gap The gap between the blades of the spinner, in radians. Default is
#' pi/5, or 36°.
#' @param stroke The stroke thickness of the individual arcs that make up each
#' blade of the spinner, in pixels. Default is 2.5.
#' @param min_radius The radius of the spinner when there is only silence, in
#' pixels. Default is 30.
#' @param radius_compression The raw `[-1, 1]` amplitude of the audio is
#' compressed using `x^radius_compression` to make the spinner more responsive
#' to quiet sounds. Default is 0.8. Set to 1.0 to disable compression. (Note
#' that this only affects the visualization, not the audio playback.)
#' @param radius_overscan Use this parameter to set the maximum possible radius
#' of the spinner, relative to the width/height of the container. Default is
#' 1.1, meaning the spinner radius will be scaled such that at maximum
#' amplitude, it will be 10% larger than the container (the spinner blades
#' will be clipped). Use larger values if you're expecting generally quiet
#' audio.
#' @param steps The number of concentric arcs that make up each blade of the
#' spinner, not including the central circle. Default is 2.
#' @param blades The number of blades in the spinner. Default is 3. Set to 0 to
#' use concentric circles instead of blades.
#' @param width The width of the spinner in CSS units. Default is "125px".
#' @param height The height of the spinner in CSS units. Default is "125px".
#' @param autoplay Whether to autoplay the audio. Default is TRUE. Note that many browsers will not
#' allow autoplaying audio without user interaction; if autoplay fails, the spinner will show a
#' tooltip instructing the user to tap or click to start the audio.
#' @param autodismiss Whether to remove the spinner after the audio finishes playing. Default is FALSE.
#' @param class The class of the spinner. Default is "mx-auto" which horizontally centers the element
#' inside its container (assuming Bootstrap is loaded).
#' @param ... Additional attributes for the spinner, to be added directly to the `<audio-spinner>` element.
#' @param autoplay Whether to autoplay the audio. Default is TRUE. Note that
#' many browsers will not allow autoplaying audio without user interaction; if
#' autoplay fails, the spinner will show a tooltip instructing the user to tap
#' or click to start the audio.
#' @param autodismiss Whether to remove the spinner after the audio finishes
#' playing. Default is FALSE.
#' @param class The class of the spinner. Default is "mx-auto" which
#' horizontally centers the element inside its container (assuming Bootstrap
#' is loaded).
#' @param ... Additional attributes for the spinner, to be added directly to the
#' `<audio-spinner>` element.
#'
#' @return An HTML tag object representing the audio spinner.
#' @import htmltools
#' @import base64enc
#' @return An HTML `<audio-spinner>` tag object representing the audio spinner.
#'
#' @examples
#' @examplesIf rlang::is_interactive()
#' # Using a URL
#' audio_spinner(src = "https://example.com/audio.mp3", rpm = 15, width = "200px", height = "200px")
#' audio_spinner(
#' src = "https://example.com/audio.mp3",
#' rpm = 15,
#' width = "200px",
#' height = "200px"
#' )
#'
#' # Using a local file
#' audio_spinner(con = "path/to/local/audio.mp3", rpm = 20, width = "150px", height = "150px")
#' audio_spinner(
#' con = "path/to/local/audio.mp3",
#' rpm = 20,
#' width = "150px",
#' height = "150px"
#' )
#'
#' @export
audio_spinner <- function(
Expand Down
4 changes: 1 addition & 3 deletions r-package/R/html_deps.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#' Create HTML dependency for multimodal component
#'
#' @importFrom htmltools htmlDependency
# HTML dependency for multimodal component
multimodal_dep <- function() {
htmlDependency(
name = "multimodal",
Expand Down
39 changes: 22 additions & 17 deletions r-package/R/input_video_clip.R
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
#' A video clip input control that records short videos from webcam
#'
#' @param inputId The input slot that will be used to access the value.
#' @param reset_on_record Whether to reset the video clip input value when recording starts. If
#' TRUE, the video clip input value will become NULL at the moment the
#' Record button is pressed; if FALSE, the value will not change until
#' the user stops recording. Default is TRUE.
#' @param mime_type The MIME type of the video clip to record. By default, this is NULL,
#' which means the browser will choose a suitable MIME type for video
#' @param reset_on_record Whether to reset the video clip input value when
#' recording starts. If TRUE, the video clip input value will become NULL at
#' the moment the Record button is pressed; if FALSE, the value will not
#' change until the user stops recording. Default is TRUE.
#' @param mime_type The MIME type of the video clip to record. By default, this
#' is NULL, which means the browser will choose a suitable MIME type for video
#' recording. Common MIME types include 'video/webm' and 'video/x-matroska'.
#' @param video_bits_per_second The target video bitrate in bits per second. By default, this is NULL,
#' which means the browser will choose a suitable bitrate for video
#' recording (according to the spec, 2,500,000). This is only a
#' suggestion; the browser may choose a different bitrate.
#' @param audio_bits_per_second The target audio bitrate in bits per second. By default, this is NULL,
#' which means the browser will choose a suitable bitrate for audio
#' recording. This is only a suggestion; the browser may choose a different
#' bitrate.
#' @param video_bits_per_second The target video bitrate in bits per second. By
#' default, this is NULL, which means the browser will choose a suitable
#' bitrate for video recording (according to the spec, 2,500,000). This is
#' only a suggestion; the browser may choose a different bitrate.
#' @param audio_bits_per_second The target audio bitrate in bits per second. By
#' default, this is NULL, which means the browser will choose a suitable
#' bitrate for audio recording. This is only a suggestion; the browser may
#' choose a different bitrate.
#' @param ... Additional parameters to pass to the underlying HTML tag.
#'
#' @examplesIf rlang::is_interactive()
#' input_video_clip(
#' "clip1",
#' video_bits_per_second = 256000,
#' audio_bits_per_second = 64000,
#' style = "width: 400px; max-width: 100%;",
#' )
#'
#' @return A video clip input control that can be added to a UI definition.
#' @export
#'
#' @importFrom htmltools tag tags tagList div
#' @importFrom shiny icon
input_video_clip <- function(
inputId,
reset_on_record = TRUE,
Expand Down
9 changes: 9 additions & 0 deletions r-package/R/shinymedia-package.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#' @keywords internal
"_PACKAGE"

## usethis namespace: start
#' @import htmltools
#' @importFrom base64enc base64encode
#' @importFrom shiny icon
## usethis namespace: end
NULL
87 changes: 55 additions & 32 deletions r-package/man/audio_spinner.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading