Skip to content

Instantly share code, notes, and snippets.

@jalapic
Last active Aug 29, 2015
Embed
What would you like to do?
## app.R ##
library(shiny)
library(sortableR)
ui = shinyUI(fluidPage(
fluidRow(
,tags$h4("sortableR in Shiny - Moving plots")
,tags$div(id="veryUniqueId", class="list-group"
,tags$div(class="list-group-item", plotOutput("myPlot1"))
,tags$div(class="list-group-item", plotOutput("myPlot2"))
,tags$div(class="list-group-item", plotOutput("myPlot3"))
)
),sortableROutput( "mySort" )
)
)
server = function(input,output){
output$mySort <- renderSortableR({
sortableR("veryUniqueId")
})
output$myPlot1 <- renderPlot({
plot(table(rpois(100, 5)), type = "h", col = "red", lwd = 10,
main = "rpois(100, lambda = 5)")
})
output$myPlot2 <- renderPlot({
x <- 0:12
y <- sin(pi/5 * x)
plot(x,y)
})
output$myPlot3 <- renderPlot({
# Define 2 vectors
cars <- c(1, 3, 6, 4, 9)
trucks <- c(2, 5, 4, 5, 12)
plot(cars, type="o", col="blue", ylim=c(0,12))
lines(trucks, type="o", pch=22, lty=2, col="red")
title(main="Autos", col.main="red", font.main=4)
})
}
shinyApp(ui=ui,server=server)`
@timelyportfolio
Copy link

timelyportfolio commented Mar 4, 2015

note, you can just replace sortableROutput within ui.R for now inside of fluidPage(...) and remove all the sortableR stuff in server.R.

Loading

@timelyportfolio
Copy link

timelyportfolio commented Mar 4, 2015

also, there are a couple little bugs in the original. here is my working version.

library(shiny)
library(sortableR)


ui = shinyUI(fluidPage(
  fluidRow(
    tags$h4("sortableR in Shiny - Moving plots")
    ,tags$div(id="veryUniqueId", class="list-group"
      ,tags$div(class="list-group-item", plotOutput("myPlot1"))
      ,tags$div(class="list-group-item", plotOutput("myPlot2"))
      ,tags$div(class="list-group-item", plotOutput("myPlot3"))
    )
  )
  ,sortableR( "veryUniqueId" )
))


server = function(input,output){
   output$myPlot1 <- renderPlot({
    plot(table(rpois(100, 5)), type = "h", col = "red", lwd = 10,
         main = "rpois(100, lambda = 5)")
  })

  output$myPlot2 <- renderPlot({
    x <- 0:12
    y <- sin(pi/5 * x)
    plot(x,y)
  })

  output$myPlot3 <- renderPlot({
    # Define 2 vectors
    cars <- c(1, 3, 6, 4, 9)
    trucks <- c(2, 5, 4, 5, 12)
    plot(cars, type="o", col="blue", ylim=c(0,12))
    lines(trucks, type="o", pch=22, lty=2, col="red")
    title(main="Autos", col.main="red", font.main=4)
  })


}

shinyApp(ui=ui,server=server)

Loading

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