Created
August 19, 2013 19:46
-
-
Save tcash21/6273218 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
.chart_container { | |
position: relative; | |
display: inline-block; | |
font-family: Arial, Helvetica, sans-serif; | |
} | |
.rChart { | |
display: inline-block; | |
margin-left: 40px; | |
} | |
.yAxis { | |
position: absolute; | |
top: 0; | |
bottom: 0; | |
width: 40px; | |
} | |
.legend { | |
position: absolute; | |
top: 0; | |
right: -160px; | |
vertical-align: top; | |
} | |
.slider { | |
margin-left: 40px; | |
margin-top: 12px; | |
} | |
#text { | |
position: relative; | |
bottom: -35px; | |
right: -65px; | |
} |
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
require(shiny) | |
require(rCharts) | |
inputChoices <- c("A", "B", "C", "D") | |
shinyServer(function(input, output, session){ | |
input2Choices <- reactive({ | |
inputChoices[-grep(input$input1, inputChoices)] | |
}) | |
output$input1 <- renderUI({ | |
selectInput("input1", "Input 1:", choices=as.list(inputChoices)) | |
}) | |
output$input2 <- renderUI({ | |
if(is.null(input$input1)) | |
return() | |
selectInput("input2", "Input 2:", choices=input2Choices()) | |
}) | |
dataInput1 <- reactive({ | |
if(is.null(input$input1)) | |
return() | |
switch(input$input1, | |
"A" = 1, | |
"B" = 2, | |
"C" = 3, | |
"D" = 4) | |
}) | |
dataInput2 <- reactive({ | |
if(is.null(input$input2)) | |
return() | |
switch(input$input2, | |
"A" = 1, | |
"B" = 2, | |
"C" = 3, | |
"D" = 4) | |
}) | |
getData <- function(){ | |
data1 <- dataInput1() | |
data2 <- dataInput2() | |
return(mtcars) | |
} | |
output$text <- renderTable({ | |
head(getData()) | |
}) | |
output$show <- renderChart2({ | |
if(is.null(input$input1) | is.null(input$input2)){ | |
return(Rickshaw$new()) | |
} | |
if (input$input1 == input$input2){ | |
return(Rickshaw$new()) | |
} | |
usp = reshape2::melt(USPersonalExpenditure) | |
p4 <- Rickshaw$new() | |
p4$layer(value ~ Var2, group = 'Var1', data = usp, type = 'line') | |
p4$set(width = 600, slider = TRUE) | |
p4$print("chart6") | |
p4 | |
}) | |
}) |
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
require(shiny) | |
require(rCharts) | |
shinyUI(pageWithSidebar( | |
headerPanel("Dynamic UI inputs with Shiny"), | |
sidebarPanel( | |
includeCSS('app.css'), | |
uiOutput('input1'), | |
uiOutput('input2') | |
), | |
mainPanel( | |
showOutput("show", "rickshaw"), | |
#verbatimTextOutput("show") | |
tableOutput("text") | |
) | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment