I want to plot with R shiny the variables contained in a data frame. I would hence have several plots, that is several renderPlot functions, but I want to create that data frame only once. I therefore look for a way to do something like
library(shiny)
server <- shinyServer(function(input, output, session) {
## Creating and plotting the dataframe
## Calling renderPlot
output$plotxy <- renderPlot({
x = c(1,2,3)
y = c(4,5,6)
z = c(7,8,9)
d = data.frame( x, y, z )
plot( d$x, d$y )
})
output$plotxz <- renderPlot({
x = c(1,2,3)
y = c(4,5,6)
z = c(7,8,9)
d = data.frame( x, y, z )
plot( d$x, d$z )
})
output$plotzy <- renderPlot({
x = c(1,2,3)
y = c(4,5,6)
z = c(7,8,9)
d = data.frame( x, y, z )
plot( d$z, d$y )
})
})
ui <- shinyUI(
fluidPage(
plotOutput("plotxy"),
plotOutput("plotxz"),
plotOutput("plotzy")
)
)
shinyApp(ui = ui, server = server)
Would create the dataframe "d" as a global variable be a good idea? Any tip?