r - How to display input text inside some other text in shiny? -
i have input box , whenever user types name, output should "hai mr.x, how you?" x input. should appear after first input , name should change x whatever based on input after onwards.
my ui.r
, server.r
codes below:
ui.r
library(shiny) shinyui(fluidpage( titlepanel("employee assesment"), sidebarlayout( sidebarpanel( textinput("name","enter name","")), mainpanel(("about this"), textoutput("name") ) ) ))
server.r
library(shiny) shinyserver(function(input, output) { output$name <- rendertext({input$name}) })
i think there couple things need addressed in question. first of all, place put server logic, such drives specific output, in server function. in rendertext
function, can put type of interactive expression. in case, might be
output$name <- rendertext({ if(input$name != ""){ paste0("oh hai mr. ", input$name, ". how you?" } })
at same time, doesn't have control flow other not displaying while name blank. instead, might want consider adding submitbutton
or actionbutton
in order allow people submit name once finished typing this.
here how include that:
sidebarpanel( textinput("name","enter name",""), actionbutton(inputid = "submit",label = "submit") )
to access actionbutton's control flow, can set reactive expression triggered event. example, going call "name."
name <- eventreactive(input$submit, { if(input$name != ""){ paste0("oh hai mr. ", input$name, ". how you?") } else { "please write name." } })
then when want refer it, can use in our call output$name so:
output$name <- rendertext({ name() })
this way, people's names appear once have written name, , otherwise error message prompting them write something.
Comments
Post a Comment