Skip to content

Instantly share code, notes, and snippets.

@jalapic
Created March 4, 2015 02:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jalapic/53fb11cb35bab586b021 to your computer and use it in GitHub Desktop.
Save jalapic/53fb11cb35bab586b021 to your computer and use it in GitHub Desktop.
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)
@jalapic
Copy link
Author

jalapic commented Mar 4, 2015

Generally works well - really easy to move the widgets around to please the user. Next step will be to do multiple plots and to try to move those around.

issue1: When changing the text input the shinyapp will crash and be non-recoverable. i.e. it won't simply give a warning which you can override by typing in an appropriate color. It won't allow you too.

@timelyportfolio
Copy link

Strange on issue 1. I'm really interested in how to to drag/drop variable names using group parameter into a plot for inspection or to change axes. Let me know if you do anything on this.

Thanks so much for trying this out. I'm still trying to wrap my ahead around all the potential.

@jalapic
Copy link
Author

jalapic commented Mar 4, 2015

Great idea about variable name drop ins - hope to try that tomorrow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment