Created
March 4, 2015 02:33
-
-
Save jalapic/53fb11cb35bab586b021 to your computer and use it in GitHub Desktop.
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(sortableR) | |
library(ggplot2) | |
ui = shinyUI(fluidPage( | |
fluidRow( | |
column( width = 4 | |
,tags$h4("sortableR in Shiny - Moving widgets") | |
,tags$div(id="veryUniqueId", class="list-group" | |
,tags$div(class="list-group-item", sliderInput("slider", "Slide me:", min = 10, max = 500, value = 275)) | |
,tags$div(class="list-group-item", textInput("text", label = h3("Enter color name:"), value = "dodgerblue")) | |
,tags$div(class="list-group-item", checkboxInput("checkbox", label = "Add mean line?", value = T)) | |
,tags$div(class="list-group-item", actionButton("goButton", "Go!"), | |
p("Click the button to get a new random sample of the same size.")) | |
) | |
),sortableROutput( "mySort" ), | |
column(width = 8, | |
wellPanel( | |
plotOutput("myPlot") | |
) | |
)) | |
) | |
) | |
server = function(input,output){ | |
output$mySort <- renderSortableR({ | |
sortableR("veryUniqueId") | |
}) | |
mydata <- reactive({ | |
input$goButton | |
vals <- rnorm(input$slider, 35, 15) | |
}) | |
output$myPlot <- renderPlot({ | |
x <- data.frame(vals = mydata()) | |
g <- ggplot(x, aes(vals)) + geom_bar(color="black", fill=input$text) + theme_bw() | |
if (input$checkbox==T){ | |
g + geom_vline(xintercept=mean(x$vals), lwd=1, lty=2, color="red") | |
} | |
else | |
g | |
}) | |
} | |
shinyApp(ui=ui,server=server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great idea about variable name drop ins - hope to try that tomorrow