Is there a refresh rate parameter for textInput() ?

68 views
Skip to first unread message

Max Geraschenko

unread,
Sep 24, 2016, 7:43:15 PM9/24/16
to Shiny - Web Framework for R
I see many people use textInput() to take a text string. How does it understand when I have stopped typing? For instance, I use textInput() to search for a name in my database. I'd like to find "Bobby" but let's pretend I am a slow typer so I get "Bob" and pause for a second. The Shiny script will try to find "Bob" and, if the name is not on the list, refreshes the window with some warning message. If I am a super slow typer, I will get warnings after every letter B,o,b,b. 
Is it possible to change the maximum allowed delay between character typing before Shiny will try to refresh the value?
Can I add some "end of input" confirmation ?

Thank you,
Maxim

David Ruvolo

unread,
Sep 25, 2016, 5:02:18 PM9/25/16
to Shiny - Web Framework for R
One example is to add an actionButton("mybutton",...), which will prevent the warnings. In the server, wrap observeEvent(input$mybutton,{...}) around output$mytext <- renderText({...}) or whatever you desire (e.g., reactive, renderPlot, renderTable, etc.). See example below:

library(shiny)

## shinyUI
ui <- fluidPage(
    
    ## make title
    titlePanel("Text Demonstration"),
    
    br(), ## just a little space for visual ease
    
    ## make Main
    mainPanel(
        ## one row w/ 3 cols
        fluidRow(
            ## col 1 - label for col 2
            column(3, HTML("<h4>1. Find Name</h4>")),
            ## col 2 - input
            column(4, textInput(inputId = "inputText", width = "400px",label = NULL,
                                placeholder = "e.g., John, Jane, etc.")
            ),
            ## col 3 - make button
            actionButton(inputId = "go", label = "Go!")
        ),
        
        ## row two, display output
        fluidRow(column(3, textOutput("outputText")))
    )
)

## server
server <- (function(input, output){
    
    ## make observe event
    observeEvent(input$go,{
        
        ## render Text  
        output$outputText <- renderText({
            out <- paste0("You've entered: ", input$inputText)
            return(out)
        })
        
    })
    
})

## runApp
shinyApp(ui = ui, server = server)

For more info on usage see:



Hope that helps.

- DCR

Max Geraschenko

unread,
Sep 25, 2016, 8:47:26 PM9/25/16
to Shiny - Web Framework for R
Thank you David, this is exactly what I was looking for
Reply all
Reply to author
Forward
0 new messages