from shinymedia import input_video_clip
input_video_clip("clip1",
=256000,
video_bits_per_second=64000,
audio_bits_per_second="width: 400px; max-width: 100%;",
style )
shinymedia
shinymedia is a Python and R package that provides Shiny UI controls for recording and playing back media.
At this time it includes two components:
input_video_clip
for recording video clips using attached camerasaudio_spinner
for playing back audio with a spinning visualization
You can see these two components in action together in our live demo (source code), or keep reading.
Installation
From PyPI:
pip install shinymedia
Or to install the latest from GitHub:
pip install "shinymedia @ git+https://github.com/posit-dev/shinymedia?subdirectory=python-package"
From CRAN:
install.packages("shinymedia") # Not published yet
Or to install the latest from GitHub:
pak::pak("posit-dev/shinymedia/r-package")
Recording video with input_video_clip
This component allows you to record video clips using attached cameras. Press the Record button to start recording, and press Stop to stop. The recorded clip will be sent to Shiny as a data URI in whatever video format the browser supports.
The example below lets you see what the component looks like, although it won’t actually do anything with the recorded video in this static document.
library(shinymedia)
input_video_clip(
"clip1",
video_bits_per_second=256000,
audio_bits_per_second=64000,
style="width: 400px; max-width: 100%;",
)
Visualizing audio with audio_spinner
Plays audio with a visualization that spins and pulses in time with the audio signal.
Note that audio_spinner
is not a reactive Shiny output, just a regular HTML component. To render a audio_spinner
reactively, you can create a dynamic output by using @render.express
or @render.ui
and including an audio_spinner
in the output.
Click the icon to play.1
from shinymedia import audio_spinner
audio_spinner(='mp3/essaisurlesrevolutions_00_chateaubriand_64kb.mp3',
src="125px",
width="125px",
height=False,
autoplay )
library(shinymedia)
audio_spinner(
con = 'mp3/essaisurlesrevolutions_00_chateaubriand_64kb.mp3',
width = "125px",
height = "125px",
autoplay = FALSE,
)
There are many options for customizing the appearance and behavior of the spinner. Here is an example with a dark background, faster rotation, more blades, and a thinner stroke. See the reference docs for more information on these and other options.
from shinymedia import audio_spinner
audio_spinner(='mp3/essaisurlesrevolutions_00_chateaubriand_64kb.mp3',
src="bg-dark rounded-3 mx-auto",
class_="125px",
width="125px",
height=False,
autoplay=33,
rpm=8,
blades=0.2,
gap=1,
stroke=5,
steps )
library(shinymedia)
audio_spinner(
con = 'mp3/essaisurlesrevolutions_00_chateaubriand_64kb.mp3',
class = "bg-dark rounded-3 mx-auto",
width = "125px",
height = "125px",
autoplay = FALSE,
rpm = 33,
blades = 8,
gap = 0.2,
stroke = 1,
steps = 5,
)
Footnotes
Audio credit: LibriVox recording of Essai sur les révolutions suivi des Etudes historiques by François-René de Chateaubriand, public domain.↩︎