ℕʘʘḆḽḘ
ℕʘʘḆḽḘ

Reputation: 19405

simple shiny app with input text and output text

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!

Upvotes: 0

Views: 1827

Answers (1)

Ronak Shah
Ronak Shah

Reputation: 389315

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

Upvotes: 2

Related Questions