Skip to content

Instantly share code, notes, and snippets.

@pssguy
Created December 20, 2013 22:00
Show Gist options
  • Save pssguy/8062364 to your computer and use it in GitHub Desktop.
Save pssguy/8062364 to your computer and use it in GitHub Desktop.
Shiny Nvigation Test
shinyServer(function(input, output, session) {
## code for Distribution option
output$distPlot <- renderPlot({
# generate an rnorm distribution and plot it
dist <- rnorm(input$obs)
hist(dist)
})
## code for Diamonds Option
dataset <- reactive({
diamonds[sample(nrow(diamonds), input$sampleSize),]
})
output$plot <- renderPlot({
p <- ggplot(dataset(), aes_string(x=input$x, y=input$y)) + geom_point()
if (input$color != 'None')
p <- p + aes_string(color=input$color)
facets <- paste(input$facet_row, '~', input$facet_col)
if (facets != '. ~ .')
p <- p + facet_grid(facets)
if (input$jitter)
p <- p + geom_jitter()
if (input$smooth)
p <- p + geom_smooth()
print(p)
}, height=400)
})
library(shiny)
library(ggplot2)
dataset <- diamonds
shinyUI(navbarPage(
tags$head(
tags$link(rel = 'stylesheet', type = 'text/css', href = 'styles.css')
),
title = "navbar Example", header="optional header",footer="optional footer",inverse=TRUE,
collapsable = TRUE,
tabPanel(title="Diamonds",
titlePanel("Diamonds Explorer"),
plotOutput('plot'),
hr(),
fluidRow(
column(3,
h4("Select Options"),
sliderInput('sampleSize', 'Sample Size',
min=1, max=nrow(dataset), value=min(1000, nrow(dataset)),
step=500, round=0),
br(),
checkboxInput('jitter', 'Jitter'),
checkboxInput('smooth', 'Smooth')
),
column(4, offset = 1, #The offset parameter is used on the center input column to provide custom spacing between the first and second columns.
selectInput('x', 'X', names(dataset)),
selectInput('y', 'Y', names(dataset), names(dataset)[[2]]),
selectInput('color', 'Color', c('None', names(dataset)))
),
column(4,
selectInput('facet_row', 'Facet Row', c(None='.', names(dataset))),
selectInput('facet_col', 'Facet Column', c(None='.', names(dataset)))
)
)
),
tabPanel(title= "Distribution",
titlePanel("Hello Shiny!"),
sidebarLayout(position = "left",fluid= TRUE,
sidebarPanel(
sliderInput("obs", "Number of observations:",
min = 1, max = 1000, value = 500)
),
mainPanel(
plotOutput("distPlot")
)
)),
navbarMenu("Sports", #collapsable = TRUE,
tabPanel("Baseball"),
tabPanel("Soccer"))
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment