Created
March 12, 2015 17:24
-
-
Save Nicolabo/3cc44e928840075fa093 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 <- list("Value1" = "AT1", "Value2" = "AT2", | |
"Value3" = "AT3", "Value4" = "AT4", | |
"Value5" = "AT5", "Value6" = "RT1", | |
"Value7" = "AT6", "Value8" = "AT7", | |
"Value9" = "AT8", "Value10" = "AT9", | |
"Value11" = "AT10", "Value12" = "RT2") | |
levele <- c("AT1","AT2","AT3","AT4","AT5","RT1","AT6","AT7","AT8","AT9","AT10","RT2") | |
number_value1 <- sample(1:100,12) | |
number_value2 <- sample(1:100,12) | |
number_value3 <- sample(1:100,12) | |
number_value4 <- sample(1:100,12) | |
df1 <- data.frame(value = levele,number = number_value1, number2 = number_value2, order = 1:12) | |
df2 <- data.frame(value = levele,number = number_value3, number2 = number_value4, order = 1:12) | |
df1$value <- factor(df1$value, levels = levele) | |
df2$value <- factor(df2$value, levels = levele) | |
axis_vars_y <- c("number","number2") | |
axis_vars_x <- c("value", "order","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) | |
# packageurl <- "http://cran.r-project.org/src/contrib/Archive/dplyr/dplyr_0.3.tar.gz" | |
# install.packages(packageurl, repos=NULL, type="source") | |
# sessionInfo() | |
# packageVersion("shiny") | |
# library(httpuv) | |
# packageVersion("dplyr") | |
# devtools::install_github("hadley/dplyr") | |
# packageVersion("dplyr") | |
# packageVersion("shiny") | |
packageVersion("ggvis") | |
shinyServer(function(input, output,session) { | |
datasetInput <- reactive({ | |
switch(input$dataset, | |
df2 = df2, | |
df1 = df1) | |
}) | |
axis_vara_y <- reactive({ | |
switch(input$yvar, | |
number = 2, | |
number2 = 3) | |
}) | |
output$slider <- renderUI({ | |
sliderInput("inslider",h5(""), min = round(min(datasetInput()[,axis_vara_y()]),0)-1, | |
max = round(max(datasetInput()[,axis_vara_y()]),0)+1, | |
value = c(round(min(datasetInput()[,axis_vara_y()]),0)-1, | |
round(max(datasetInput()[,axis_vara_y()]),0)+1), | |
step = 0.5) | |
}) | |
#------------------------------------------------------------------------------------------------------------------------ | |
data <- reactive({ | |
filteredData <- datasetInput() | |
axisData <- axis_vara_y() | |
if(!is.null(input$inslider)){ | |
if(input$radio == "All values"){ | |
filteredData <- filteredData %>% | |
filter(filteredData[,axisData] >= input$inslider[1], | |
filteredData[,axisData] <= input$inslider[2]) | |
} | |
else { | |
filteredData <- filteredData %>% | |
filter(value %in% input$checkGroup, | |
filteredData[,axisData] >= input$inslider[1], | |
filteredData[,axisData] <= input$inslider[2]) | |
} | |
} | |
return(filteredData) | |
}) | |
data_point <- reactive({ | |
data() %>% | |
mutate(id = row_number()) | |
}) | |
#------------------------------------------------------------------------------------------------------------------------ | |
# diff_tooltip <- function(x) {...} | |
dotpoint_vis <- reactive({ | |
xvar_name <- names(axis_vars_x)[axis_vars_x == input$xvar] | |
yvar_name <- names(axis_vars_y)[axis_vars_y == input$yvar] | |
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 = ~value) %>% | |
add_axis("x", title = xvar_name) %>% | |
add_axis("y", title = yvar_name) %>% | |
set_options(width = 750, height = 500) | |
# if (length(unique(data_point()[,input$yvar])) != 1){ | |
# plot | |
# } | |
# else{ | |
# if (input$xvar == "Difficulty" | input$xvar == "Discrimination"){ | |
# plot %>% | |
# scale_numeric("y", domain = c(data_point()[1,input$yvar] -0.5, | |
# data_point()[1,input$yvar] +0.5),clamp = T) %>% | |
# scale_numeric("x", domain = c(data_point()[1,input$xvar] -0.5, | |
# data_point()[1,input$xvar] +0.5),clamp = T) | |
# } | |
# else{ | |
# plot %>% | |
# scale_numeric("y", domain = c(data_point()[1,input$yvar] -0.5, | |
# data_point()[1,input$yvar] +0.5),clamp = T) | |
# } | |
# } | |
}) | |
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( | |
radioButtons("radio",h5("Select"),choices=list("All values","Selected values"), | |
selected="All values"), | |
conditionalPanel( | |
condition = "input.radio != 'All values'", | |
checkboxGroupInput("checkGroup",label = "", | |
choices, | |
selected = c("AT1","AT2")) | |
), | |
hr(), | |
radioButtons("dataset", label = h5("Drilldown"), | |
choices = list("2 Level" = "df1", "3 Level" = "df2") | |
), | |
hr(), | |
h5("Choice"), | |
selectInput("xvar", h6(""), | |
axis_vars_x, | |
selected = "value"), | |
selectInput("yvar", h6(""), | |
axis_vars_y, | |
selected = "number2"), | |
hr(), | |
uiOutput("slider") | |
) | |
), | |
column(9, | |
ggvisOutput("plot") | |
) | |
) | |
) | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment