knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) library(shinyDTC)
The shinyDTC
package is designed to provide a versatile timer widget for Shiny applications. This timer functionality allows developers to add precise control over timing in their interactive tools, supporting features like adjustable speeds, step-by-step controls, and reset options. Whether for simulations, animations, or user-controlled processes, shinyDTC
enables seamless integration of timing elements into Shiny applications. This vignette explores the core timer functions and demonstrates their usage alongside example applications.
To begin using the shinyDTC
package, you need to install it. If the package is available on CRAN, you can use the standard installation command. Alternatively, if the package is hosted on GitHub, use devtools
to install it directly from the repository.
# From CRAN install.packages("shinyDTC") # From GitHub devtools::install_github("sigbertklinke/shinyDTC")
Once installed, load the package with library("shinyDTC")
and you're ready to explore its features.
In addition to managing example applications, shinyDTC
provides robust tools for incorporating timers into Shiny applications. Timers can be used to control animations, trigger periodic events, or manage user interaction.
timerInput
The timerInput
function generates a user interface component that combines a slider for speed control with buttons for step and reset actions. This component is useful for creating interactive controls that adjust the timing of events within your application.
ui <- fluidPage( timerInput("my_timer", label = "Timer Controller", max = 100) ) server <- function(input, output, session) { # Timer logic can be added here } shinyApp(ui, server)
Once a timer input has been created, you may want to update its state dynamically based on user actions or other events. The updateTimerInput
function allows you to programmatically modify the timer's speed, step, and reset controls.
observeEvent(input$some_event, { updateTimerInput(session, "my_timer", value = 50) })
shinyDTC
also provides utility functions like stepTimer
and resetTimer
, which simulate button presses for the step and reset actions, respectively. These functions are particularly useful when you want to programmatically control the timer's behavior.
# Trigger the step button stepTimer("my_timer") # Reset the timer resetTimer("my_timer")
openApp
and runAppx
Another functionality of shinyDTC
is managing and launching example Shiny applications. The openApp
function allows you to quickly open a specific example application provided within the package. By specifying the dir
parameter, you can select the desired example from the available options. If the specified directory does not match any of the available examples, an error message will be displayed.
# A minimal example runAppx()
The runAppx
function extends this capability by allowing you to pass additional data to the application. This function not only launches the application but also enables seamless integration of custom datasets. For example, you can provide a data frame as input, which will then be available for use within the Shiny application.
# Launch the "mini" application with additional data data <- data.frame(a = 1:10, b = 11:20) runAppx(example = "mini", x = data) # runAppx("mini", data) would be OK too
If you are unsure which example applications are available, you can retrieve a list of options by inspecting the directories under system.file('examples-shiny', package='shinyDTC')
.
This Shiny web application demonstrates the use of the shinyDTC
timer widget for dynamic control over time-based interactions. The application provides an intuitive interface with a timer slider and buttons to control the timing behavior.
Features: 1. Timer Slider: Adjust the speed of the timer interactively. 2. Step and Reset Buttons: + The Step button advances the timer by one unit. + The Reset button resets the timer to zero. 3. Dynamic Feedback: The main panel displays the current timer value (t) in real-time, allowing users to see the immediate effects of their inputs.
How to Use:
runAppx()
This example showcases how to seamlessly integrate and utilize shinyDTC
's timer features within a Shiny application, enabling developers to build more interactive and responsive user interfaces.
The app is a dynamic web application designed to help users explore and visualize various clustering algorithms. With an interactive user interface, the app provides real-time clustering results based on popular methods, including K-Means, K-Median, K-Means++, and K-Medoid. By adjusting parameters such as the number of clusters and the clustering method, users can see how the data is grouped and observe the convergence of clustering algorithms.
runAppx("kmeans", faithful) # Default data set
Key Features:
How It Works:
Application Use Cases:
This app is perfect for anyone interested in clustering techniques, from data science beginners to experienced analysts looking for a visual representation of the clustering process.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.