Last active
August 29, 2015 14:16
-
-
Save jalapic/76f1d9c5789dcbbc9860 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
## 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)` | |
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)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
note, you can just replace
sortableROutput
withinui.R
for now inside offluidPage(...)
and remove all thesortableR
stuff inserver.R
.