I'm using R shiny in combination with ggplot to visualize a certain dataset. I want the user to be able to add values to this dataset. I can get my application so far as to show me the original data + one data point, but as soon as the user enters a new point, the old one is gone: the user-input data is not actually stored in my dataframe.
Some of the code I'm using (changed variable names for simplicity):
shinyServer(
function(input, output) {
output$newPlot <- renderPlot({
input$addButton
isolate({
x <- as.numeric(input$x)
y <- as.numeric(input$y)
if (!is.na(y)) {
data <- rbind(data, data.frame(x = x, y = y))
# more code here
}
# more code here
plot <- myPlot(data)
print(plot)
})
})
}
)
The user can give values for x and y with textInput
and then submit those values with a button (actionButton
). Each time the user hits 'add', the most recently inputted values for x and y are shown on top of the original data, but any other values the user inputted (in the same session) are lost. How do I get shiny to remember my users inputs and plot all of it?