1

I have created a text prediction app that displays 10 sentences based on the word searched in the toolbar. However, all the sentences are being displayed in a single toolbar horizontally. I would like the sentences to appear sequentially i.e. vertically, one after another

    ui<- shinyUI(fluidPage(
  
  # Application title
  mainPanel(
   img(src='image.jpg', align = "right"),
 
  #titlePanel(title=div(img(src="spsimage.jpg"))),
  
  fluidRow(HTML("<strong> Search Bar")),
  #fluidRow(HTML(" <strong>Date: 06-29-2020</strong>") ),
  
  fluidRow(
    br(),
    p("Text predictior app ")),
  br(),
  br(),
  
  fluidRow(HTML("<strong>Enter a word. Press \"Next words\" button to predict the following words</strong>") ),
  fluidRow( p("\n") ),
  
  # Sidebar layout
  sidebarLayout(
    
    sidebarPanel(
      textInput("inputString", "Enter a word here",value = " "),
      submitButton("Next words")
    ),
    
    mainPanel(
      h4("Predicted Next Word"),
      verbatimTextOutput("prediction"),
      textOutput('text1'),
      
    )
  )
)))


server <- function(input, output, session) {
  sentences <- reactive({
    make_sentences(input$inputString)
  })
  output$prediction <- renderText({ sentences() })
}

the output is coming as - Angry look for some time for Angry glance, and the duc d’enghien Angry look was a tone or Angry tears. “Lise!” Was that? The Angry tears. “Lise!” Said princess anna Angry look as much as she Angry look for three of the Angry tears. “Lise!” Said to the Angry look fixed on with an Angry glance, and fireworks are not

I would prefer -

1- Angry look for some time for
2- Angry glance, and the duc d’enghien
3- Angry look was a tone or Angry tears. “Lise!” Was that? 
4-The Angry tears. “Lise!” Said princess anna 
5-Angry look as much as she
'''''
Vikram
  • 83
  • 7

1 Answers1

2

Please provide a reprex -this will increase the likelihood to get a useful answer.

In general: textOutput and verbatimTextOutput are two different output elements, where the latter is used to format objects similar to the R console and should be used with renderPrint. The former should be used with renderText, it does however ignore linebreaks.

If you want to have text output with linebreaks you have to add <br/> tags manually and fall back to uiOutput/renderUI.

Compare the output in the following app:

library(shiny)
out <- list(vec = paste("sentence", 1:5))
out$string <- paste(out$vec, collapse = "<br/>\n")

ui <- fluidPage(selectInput("which", "Selector:", names(out)),
                h3("Text Output"),
                textOutput("text"),
                h3("Verbatim Text Output"),
                verbatimTextOutput("verb"),
                h3("UI Output"),
                uiOutput("ui")
)

server <- function(input, output, session) {
  output$text <- renderText(out[[input$which]])
  output$verb <- renderPrint(out[[input$which]])
  output$ui <- renderUI(HTML(out[[input$which]]))
}

shinyApp(ui, server)

thothal
  • 16,690
  • 3
  • 36
  • 71