Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@jalapic 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

This comment has been minimized.

Copy link

@timelyportfolio timelyportfolio commented Mar 4, 2015

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

This comment has been minimized.

Copy link
Owner Author

@jalapic 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