Created
March 25, 2015 14:44
-
-
Save Nicolabo/e6ba9b61a1ecdb518fbd to your computer and use it in GitHub Desktop.
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
choices <- c("Value1", "Value2", | |
"Value3", "Value4", | |
"Value5", "Value6", | |
"Value7", "Value8", | |
"Value9", "Value10", | |
"Value11", "Value12") | |
levele <- c("AT1","AT2","AT3","AT4","AT5","RT1","AT6","AT7","AT8","AT9","AT10","RT2") | |
number_value1 <- sample(1:100,22) | |
number_value2 <- sample(1:100,22) | |
number_value3 <- sample(1:100,50) | |
number_value4 <- sample(1:100,50) | |
df1 <- data.frame(product = c(rep("Product1",12),rep("Product2",10)), name = c(choices,choices[1:10]), | |
short_name = c(levele,levele[1:10]),number = number_value1, number2 = number_value2) | |
df2 <- data.frame(product = c(rep("Product1",30),rep("Product2",20)), name = c(rep(choices,2),choices[1:6],rep(choices[1:10],2)), | |
short_name = c(rep(levele,2),levele[1:6],rep(levele[1:10],2)),number = number_value3, number2 = number_value4) | |
df1$name <- factor(df1$name, levels = choices) | |
df1$short_name <- factor(df1$short_name, levels = levele) | |
df2$name <- factor(df2$name, levels = choices) | |
df2$short_name <- factor(df2$short_name, levels = levele) | |
axis_vars_y <- c("number","number2") | |
axis_vars_x <- c("name","number","number2") |
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(dplyr) | |
library(ggvis) | |
shinyServer(function(input, output,session) { | |
datasetInput <- reactive({ | |
switch(input$dataset, | |
df2 = df2, | |
df1 = df1) | |
}) | |
data <- reactive({ | |
filteredData <- datasetInput() | |
if(input$radio == "All values"){ | |
filteredData <- filteredData %>% | |
filter(product == input$product) | |
} | |
else { | |
filteredData <- filteredData %>% | |
filter( | |
name %in% input$testname, | |
product == input$product) | |
} | |
return(filteredData) | |
}) | |
data_point <- reactive({ | |
data() %>% | |
mutate(id = row_number()) | |
}) | |
dotpoint_vis <- reactive({ | |
xvar <- prop("x",as.symbol(input$xvar)) | |
yvar <- prop("y",as.symbol(input$yvar)) | |
plot <- data_point %>% | |
ggvis(x = xvar,y = yvar) %>% | |
layer_points(size := 120,fill = ~short_name) %>% | |
set_options(width = 750, height = 500) | |
}) | |
dotpoint_vis %>% bind_shiny("plot") | |
}) |
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(ggvis) | |
library(markdown) | |
library(shiny) | |
library(dplyr) | |
library(magrittr) | |
shinyUI( | |
fluidPage( | |
h3("Title"), | |
fluidRow( | |
column(3, | |
wellPanel( | |
selectInput("product", h3("Select product"), | |
choices = list("Product1","Product2"), | |
selected = "Product1"), | |
radioButtons("radio",h5("Select"),choices=list("All values","Selected values"), | |
selected="All values"), | |
conditionalPanel( | |
condition = "input.radio != 'All values'", | |
checkboxGroupInput("testname",label = "", | |
choices, | |
selected = c(choices[1],choices[2])) | |
), | |
radioButtons("dataset", label = h5("Choose Dataframe"), | |
choices = list("2 Level" = "df1", "3 Level" = "df2") | |
), | |
h5("Choice"), | |
selectInput("xvar", h6(""), | |
axis_vars_x, | |
selected = "value"), | |
selectInput("yvar", h6(""), | |
axis_vars_y, | |
selected = "number2") | |
) | |
), | |
column(9, | |
ggvisOutput("plot") | |
) | |
) | |
) | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment