Reputation: 101
I have the following r shiny application. We first import the library
library(shiny)
Now we generate the UI
ui <- fluidPage(
downloadButton("dl", "Download"),
textInput("text","word inpput"),
mainPanel(
tableOutput("text1")
))
Next we generate the server
server <- function(input, output) {
output$text1 <- renderTable({
df1<-iris
df1$text <- input$text
return(df1)
})
}
Finally run the app
shinyApp(ui, server)
We can now add a text to the textbox to dd to the column text in the dataframe output. However, if i remove the word, the dataframe output reverts to its original state owing to reactivity. Is there a way that the change in output can be made permanent so that even if the textinput box value is replaced, the old value reflects along with the new value
Upvotes: 1
Views: 192
Reputation: 2725
Assuming I understand correctly, please test the below and let me know if it solves your problem or what still needs to be achieved:
server <- function(input, output) {
values <- reactiveValues(df1 = iris)
observeEvent(req(input$text != ""), {
values$df1[, paste0("text", ncol(values$df1)-ncol(iris))] <- input$text
})
output$text1 <- renderTable({
return(values$df1)
})
}
Upvotes: 1