1
votes

I am trying to write a little shiny app that takes code entered into a textInput field, and when I press a button, displays it underneath the textInput. I don't want it to automatically update as I'm typing.

It works once, but after I hit the actionButton, the text in the verbatimTextOutput starts updating as I type. How can I stop this so that the verbatinTextOutput only updates when I hit the applyButton? Should I even be using verbatinTextOutput? Thanks.

server.R

library(shiny)

shinyServer(function(input, output) {

    # You can access the value of the widget with input$text, e.g.

    observeEvent(input$doBtn, {
        #... # do some work
        output$value <- renderPrint({input$text})
        #... # do some more work
   })
})

ui.R

library(shiny)
shinyUI(fluidPage(

    # Copy the line below to make a text input box
    textInput("text", label = h3("Text input"), value = "Enter text..."),
    actionButton("doBtn", "Do something"),    
    hr(),

    fluidRow(column(3, verbatimTextOutput("value")))   
))
1

1 Answers

1
votes

Figured it out.

server.R

library(shiny)
shinyServer(function(input, output) {

    output$value <- renderText({
    if (input$doBtn == 0)
        return()

    isolate({input$text})
    })    
})