I'm creating an R Shiny app for data exploration for different runs of an experiment. I have different sliderInput
and selectInput
to play with the data ranges and variables being plotted. The data is obtained via an API call to a private database.
CODE
ui <- fluidPage(
sliderInput(inputId = "num",
label = "Experiment Id",
value = 5, min = 2, max = 7),
selectInput("x", "Horizontal Axis", colopts), #colopts is predefined
selectInput("y", "Vertical Axis", colopts), #colopts is predefined
plotOutput("userPlot")
)
server <- function(input, output){
output$userPlot <- renderPlot({
# testdata is a function that makes the API call, performs cleanup, calculations etc.
# The output is a list, the first element of which is being called here
dat <- testdata(input$num)[[1]]
# "type" is hard-coded for testing - to be changed later
plt <- ggplot(dat, aes_string(x = input$x, y = input$y)) +
geom_point(aes(color = type ,fill = type, shape = type))+
geom_line(aes(color = type)) +
ggtitle(paste("Test",input$num, sep = " "))
return(plt)
})
}
shinyApp(ui = ui, server = server)
OUTPUT
It works fine, however, everytime I select a different variable to plot for either axis, the code makes another API call - which is the expected behaviour. Since the dataset being plotted changes only when a different Experiment Id is selected, I would want to make an API call only when I change the Experiment Id.
Short of loading the entire dataset into the memory and then using the app, is there a way to achieve that i.e. if only the axes are changed while keeping the Experiment Id the same, update the plot without making an API call?