r语言 - 如何在 Shiny 中给出文本预测句子的细分



我创建了一个文本预测应用程序,该应用程序根据工具栏中搜索的单词显示 10 个句子。但是,所有句子都水平显示在单个工具栏中。我希望句子按顺序出现,即垂直出现,一个接一个

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() })
}

输出是作为 - 愤怒的看着愤怒的眼神,而 duc d'enghien 愤怒的眼神是一个语气或愤怒的眼泪。"丽丝!"是吗?愤怒的眼泪。"丽丝!"说着安娜公主生气的样子和她生气地寻找三滴生气的眼泪一样。"丽丝!"对着愤怒的眼神盯着说,烟花不是

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
'''''

请提供一个 reprex - 这将增加获得有用答案的可能性。

通常:textOutputverbatimTextOutput是两个不同的输出元素,后者用于格式化类似于 R 控制台的对象,应与renderPrint一起使用。前者应该与renderText一起使用,但它确实忽略了换行符。

如果要输出带有换行符的文本,则必须手动添加<br/>标签并回退到uiOutput/renderUI

比较以下应用中的输出:

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)

最新更新