Skip to content

Instantly share code, notes, and snippets.

@cdeterman
Last active August 29, 2015 14:15
Show Gist options
  • Save cdeterman/fd6bf3955ef56fe9f38d to your computer and use it in GitHub Desktop.
Save cdeterman/fd6bf3955ef56fe9f38d to your computer and use it in GitHub Desktop.
SO 28491576
library(shiny)
library(ggvis)
library(dplyr)
shinyServer(
function(input, output, session) {
# A reactive subset of mtcars
mtc <- reactive({
mtcs <- mtcars %>%
mutate(name = row.names(.))
if (nchar(input$filter) > 0)
{
mtcs <- mtcs %>% filter(grepl(input$filter, name))
}
mtcs
})
myvis <- reactive({
myData <- mtc()
my_lb <- linked_brush(keys = 1:nrow(myData), "red")
out <- myData %>%
ggvis(~wt, ~mpg) %>%
scale_numeric("y",
domain = c(0, max(myData$mpg)),
nice=FALSE) %>%
layer_points(fill := my_lb$fill, fill.brush := 'red') %>%
my_lb$input()
return(out)
})
myvis %>% bind_shiny("plot", "plot_ui")
})
library(shiny)
library(ggvis)
shinyUI(
pageWithSidebar(
div(),
sidebarPanel(
textInput('filter', 'Filters', ''),
uiOutput("plot_ui")
),
mainPanel(
ggvisOutput("plot")
)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment