Created
July 31, 2015 21:34
-
-
Save karawoo/fa787eb0ecb0e3777fd7 to your computer and use it in GitHub Desktop.
Toggling user-selected layers with ggplot2 in a Shiny app
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") | |
library("ggplot2") | |
shinyServer(function(input, output) { | |
output$myplot <- renderPlot({ | |
## Create a boxplot with optional jittering | |
p <- ggplot(iris, aes(x = Species, y = Petal.Length)) + | |
geom_boxplot() + | |
ylab("Petal Length") | |
if (input$optlayer) { | |
p <- p + geom_jitter() | |
} | |
p | |
}) | |
}) |
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") | |
shinyUI(pageWithSidebar( | |
## App title | |
titlePanel("Toggling User-Selected Layers"), | |
# Sidebar with a layer that user can choose to add | |
sidebarPanel( | |
checkboxInput("optlayer", label = "Jitter", value = FALSE) | |
), | |
## Show plot in main panel | |
mainPanel( | |
plotOutput("myplot") | |
) | |
) | |
) |
Author
karawoo
commented
Jul 31, 2015
Lovely, nice solution to the problem :-)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment