Skip to content

Instantly share code, notes, and snippets.

@cpsievert
Created February 6, 2014 04:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cpsievert/8838380 to your computer and use it in GitHub Desktop.
Save cpsievert/8838380 to your computer and use it in GitHub Desktop.
ECDF app with shiny & ggvis
library(shiny)
library(ggvis)
x <- seq(-4, 4, .1)
dat <- data.frame(x, y=dnorm(x))
g1 <- ggvis(dat, props(x = ~x, y = ~y), mark_path())
shinyServer(function(input, output, session) {
# A subset of mtcars
dat2 <- reactive({ dat[dat$x <= input$z,] })
r_gv <- reactive({
g1 + mark_area(data=dat2, props(x = ~x, y = ~y, y2 := 410L))
})
# Set up observers for the spec and the data
observe_ggvis(r_gv, "plot1", session)
# User interface elements (in the sidebar)
output$ggvis_ui <- renderControls(r_gv, session)
output$prob <- renderPrint({
pnorm(input$z)
})
})
shinyUI(bootstrapPage(
mainPanel(
ggvis_output("plot1"),
textOutput("prob")
),
sidebarBottomPanel(
sliderInput("z", "z-score", min = -4, max = 4, value = 0, step = 0.1)
)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment