Hi!
I am new to Shiny and I am trying to learn how to handle dynamic UI. I have a scenario where the user types text into a textInput control. I am planning on parsing the contents of the textbox, but want to expose a dynamic button that when the user clicks it, it appends text. Then the process needs to continue. So for example, the user types "I am" and the button will say "hungry." When "hungry" is appended to the textbox, the button would then need to change to the next word (for example "for.")
For the moment, I am testing this with a random state to try to get the button to change:
library(shiny)
runApp(
shinyUI(fluidPage(
textInput("sentence", "Type a sentence:"),
uiOutput("uiOutputPanel"),
h6(textOutput("sentenceEntered", container=span))
))
),
server = function(input,output,session){
output$sentenceEntered <- renderText({input$sentence})
output$uiOutputPanel <- renderUI({
word1 <- sample(state.name, 1)
button1Click <- paste("$('#sentence').val($('#sentence').val() + ' ", word1, "')", sep='')
tags$button(type="button", id="word1", word1, class="btn action-button shiny-bound-input" ,
onclick=button1Click)
})
})
})
)
I assume this needs something like the "Observe" or "Reactive" construct, but everything I have tried has failed.
Is this possible, and if so, how do I accomplish it?
Thanks!
Michael