Created
January 2, 2025 21:31
-
-
Save arraytools/f5a5cf6e5a2d979fc83d47661196c31b to your computer and use it in GitHub Desktop.
A Shiny app to understand the `saturation` and `value` parameters in the rainbow() function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
# Define the UI | |
ui <- fluidPage( | |
titlePanel("Rainbow Color Palette"), | |
sidebarLayout( | |
sidebarPanel( | |
sliderInput("s_value", "Saturation (s):", min = 0, max = 1, value = 1, step = 0.01), | |
sliderInput("v_value", "Value (v):", min = 0, max = 1, value = 1, step = 0.01) | |
), | |
mainPanel( | |
plotOutput("rainbow_plot") | |
) | |
) | |
) | |
# Define the server | |
server <- function(input, output) { | |
output$rainbow_plot <- renderPlot({ | |
s <- input$s_value | |
v <- input$v_value | |
rainbow_colors <- rainbow(12, s = s, v = v) | |
# Plot the colors | |
barplot(rep(1, 12), col = rainbow_colors, border = NA, space = 0) | |
}) | |
} | |
# Run the Shiny app | |
shinyApp(ui = ui, server = server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment