0

I am trying to create the most basic shiny app. Consider this simple example

library(stringr)

input <- 'hello my friend'

output <- mytext %>% strsplit('')
> mytext %>% strsplit('')
[[1]]
 [1] "h" "e" "l" "l" "o" " " "m" "y" " " "f" "r" "i" "e" "n" "d"

All I need is a text box that asks for an input text form the user and then the program would show on another text box (say, just below the input box) the output of output.

I know how to create an input box (https://shiny.rstudio.com/reference/shiny/1.6.0/textInput.html) , but here I need to have a way to show the output of the text processing after the users enter their sentence and hit Enter.

Any ideas? Thanks!

1 Answer 1

2

Something like this?

library(shiny)

ui <- fluidPage(
  textInput('input', 'Enter input'), 
  verbatimTextOutput('output')
)

server <- function(input, output) {
  output$output <- renderText({
    req(input$input)
    strsplit(input$input, '')[[1]]
  })
}

shinyApp(ui, server)

enter image description here

Sign up to request clarification or add additional context in comments.

10 Comments

verbatimTextOutput('output') might be another option if you want something that more resembles console output.
amazing thanks! what is the purpose of the req(input$input) line?
@ℕʘʘḆḽḘ It runs strsplit(input$input, '')[[1]] line only when input is not null or not empty.
strange I am getting The application failed to start.
What happens when you copy-paste the code in the answer into the console?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.