Last active
September 29, 2016 02:33
-
-
Save ashutoshnanda/1cdab6ef87a99b21824ea9a1d122d117 to your computer and use it in GitHub Desktop.
Code from Intro to Shiny (2016 DSSC Hackathon Preparation Session)
This file contains 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) | |
shinyServer(function(input, output) { | |
data <- reactive({ | |
if(input$distribution_type == 1) { | |
rnorm(n = 500, mean = input$parameter, sd = 1) | |
} else { | |
rpois(n = 500, lambda = input$parameter) | |
} | |
}) | |
output$sample_size <- renderPrint({ | |
if(input$distribution_type == 1) { | |
print("This is a normal distribution\n") | |
} else { | |
print("This is a Poisson distribution\n") | |
} | |
print(range(data())) | |
}) | |
output$plot <- renderPlot({ | |
p <- ggplot(mapping = aes(data())) + geom_histogram(fill = "blue") + xlim(c(-5, 20)) | |
if(input$title) { | |
p + ggtitle("My Title Here") | |
} else { | |
p | |
} | |
}) | |
}) |
This file contains 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) | |
shinyUI( | |
pageWithSidebar( | |
headerPanel("My First Shiny App!"), | |
sidebarPanel( | |
h1("Sidebar"), | |
sliderInput('parameter', | |
'Parameter of Distribution', | |
min = 0.1, | |
max = 10, | |
step = 0.05, | |
value = 5), | |
selectInput('distribution_type', | |
'Distribution Type', | |
c('Normal' = 1, 'Poisson' = 2)), | |
checkboxInput('title', 'Include Title?') | |
), | |
mainPanel( | |
h1("Main Panel"), | |
textOutput('sample_size'), | |
plotOutput('plot') | |
) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment