Last active
August 29, 2015 14:15
-
-
Save cdeterman/806f51c254c523f88f01 to your computer and use it in GitHub Desktop.
SO 28673137
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
df1_number <-sample(seq(1,20,0.01),20,replace = T) | |
df1_number2 <-sample(seq(1,5,0.01),20,replace = T) | |
df1 <- data.frame(name = rep(letters[1:4],each = 5), number = df1_number, number2 = df1_number2, | |
info = "info") | |
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(ggvis) | |
library(dplyr) | |
shinyServer(function(input, output){ | |
data <- reactive({ | |
df <- df1 %>% | |
filter(name %in% input$variable) %>% | |
mutate(id = row_number()) | |
}) | |
reactive({ | |
add_info <- function(x) { | |
if(is.null(x)) return(NULL) | |
if (is.null(x$id)) return(NULL) | |
df2 <- isolate(data()) | |
df <- df2[df2$id == x$id, ] | |
paste0(df$info,"<br>", | |
df$number) | |
} | |
vis <- data() %>% | |
ggvis(~number2, ~number, fill = ~name) %>% | |
layer_points(size := 100, | |
size.hover := 240, | |
key := ~id) %>% | |
add_tooltip(add_info,"hover") | |
return(vis) | |
}) %>% bind_shiny("scatter_plot") | |
# LinePlot | |
dataset_line <- reactive({ | |
df_line <- df1 %>% | |
filter(name %in% input$variable2) | |
return(df_line) | |
}) | |
reactive({ | |
dataset_line() %>% | |
ggvis(~number2, ~number, stroke = ~name) %>% | |
layer_lines() | |
}) %>% bind_shiny("line_plot") | |
} | |
) |
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(ggvis) | |
shinyUI(fluidPage( | |
titlePanel(""), | |
sidebarLayout( | |
sidebarPanel( | |
wellPanel(checkboxGroupInput("variable",label = "", | |
choices = list("a","b","c","d"), | |
selected = c("a"))), | |
br(),br(),br(),br(),br(),br(),br(),br(), | |
wellPanel(checkboxGroupInput("variable2",label = "", | |
choices = list("a","b","c","d"), | |
selected = c("a"))) | |
), | |
mainPanel( | |
ggvisOutput("scatter_plot"), | |
ggvisOutput("line_plot") | |
) | |
) | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment