Last active
August 29, 2015 14:15
-
-
Save Nicolabo/c20502d33dee37342b2d 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
library(shiny) | |
library(dplyr) | |
df1 <- data.frame(id = c(1,2,3,4,5), number = c(20,30,23,25,34), ds = c(1,2,3,42,2)) | |
df2 <- data.frame(id = c(1,2), number = c(33,40), ds = c(1,2)) | |
shinyServer(function(input, output) { | |
datasetInput <- reactive({ | |
switch(input$dataset, | |
"df1" = df1, | |
"df2" = df2) | |
}) | |
output$yvars <- renderUI({ | |
if (identical(df1,datasetInput())){ | |
axis_vars_y <- c("number" = "number", "number2" = "number2") | |
selectInput("yvar", "X-axis variable", axis_vars_y, selected = "id") | |
} | |
else{ | |
axis_vars_y <- c("number" = "number") | |
selectInput("yvar", "X-axis variable", axis_vars_y, selected = "id") | |
} | |
}) | |
axis_vara_y <- reactive({ | |
switch(input$yvar, | |
number = 2, | |
number2 = 3) | |
}) | |
output$slider <- renderUI({ | |
sliderInput("inslider","Slider", min = min(datasetInput()[,axis_vara_y()]), | |
max = max(datasetInput()[,axis_vara_y()]), | |
value = c(min(datasetInput()[,axis_vara_y()]), | |
max(datasetInput()[,axis_vara_y()]))) | |
}) | |
data <- reactive({ | |
df<-datasetInput() | |
axisData <- 2 | |
if(!is.null(input$yvar)){ | |
axisData <- input$yvar | |
} | |
if(!is.null(input$inslider)){ | |
filteredData <- filteredData %>% | |
filter(filteredData[,axisData] >= input$inslider[1], | |
filteredData[,axisData] <= input$inslider[2]) | |
} | |
filteredData | |
}) | |
vis <- reactive({ | |
yvar <- prop("y", as.symbol(input$yvar)) | |
data %>% | |
ggvis(~id, y = yvar) %>% | |
layer_points(fill = ~factor(id)) %>% | |
scale_nominal("fill", range = c("red","blue","green","yellow","black")) | |
}) | |
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(shiny) | |
library(ggvis) | |
shinyUI(fluidPage( | |
titlePanel(""), | |
sidebarLayout( | |
sidebarPanel( | |
radioButtons("dataset", label = h4("Product level"), | |
choices = list("Item" = "df1", "Task" = "df2")), | |
uiOutput("yvars"), | |
uiOutput("slider") | |
), | |
mainPanel( | |
ggvisOutput("plot") | |
) | |
) | |
)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment