我一直在开发一个闪闪发亮的应用程序,它运行得很好(参见https://ostaski.shinyapps.io/NextWordPredictR/)。
以下是相关代码:
# ui.R
library(shiny)
library(shinyjs)
shinyUI(fluidPage(
useShinyjs(), # Set up shinyjs
titlePanel("Next Word PredictR"),
sidebarLayout(
sidebarPanel("Top Next Words",
br(" "),
shinyjs::hidden # this hides topWords, but toggleState in server.R doesn't toggle!?!
(
tableOutput('topWords')
)
),
mainPanel("Enter word(s) in the box below or click a button", # this works
br(" "),
tags$head(
tags$style(HTML("
#button1, #button2, #button3, #button4
{
color: #FFFFFF;
font-weight: bold;
background-color: #00AEAE;
border-color: #FFFFFF;
}
#text
{
width: 82%;
}
"))
),
tags$div(
tags$textarea(id = 'text', label = 'Enter word(s) in the box below or click a button', rows = 2, class='form-control', "")), # label is not working
br(" "),
htmlOutput("firstWord", inline = T),
htmlOutput("secondWord", inline = T),
htmlOutput("thirdWord", inline = T),
htmlOutput("fourthWord", inline = T),
br(" "),
p('Below are five sentences drawn from the English news corpus you can copy/paste into the box above. HINT: do not copy/paste the ellipses (...) or the next words (in bold).'),
HTML('Another strong month of hiring makes it less likely that the Federal Reserve will take additional steps to boost the economy at its meeting next ... <strong>week.</strong>'),
HTML('<br /><br />When Junior walked into the memorial service Sunday, "it was a surprise to everyone," Doug Smith, Oceanside’s postmaster, told ... <strong>me.</strong>'),
HTML('<br /><br />"The Voice," NBC’s upstart singing competition, is back for its second season Sunday, and the network is kicking it off in prime-time style -- positioning it right after the Super ... <strong>Bowl.</strong>'),
HTML('<br /><br />The main health issue that caused Meyer to resign at UF was a sick program he left on life ... <strong>support.</strong>'),
HTML('<br /><br />Scarlett Johansson filmed scenes at an old warehouse on Ashland Road near Longfellow Avenue, off Cedar Road near the Norfolk Southern railroad ... <strong>tracks.</strong>'),
HTML('<br /><br /><strong>DISCLAIMER:</strong> Yes, of course I cherry-picked these sentences. The grand majority of sentences I tested failed miserably. ☺')
)
)
)
)
# server.R
library(shiny)
library(shinyjs)
library(tm)
library(qdap)
library(dplyr)
allGrams <- readRDS("allGrams.rds")
predict <- function (inputString, allGrams)
{
...
}
shinyServer(function(input, output, session) {
observe({
...
shinyjs::toggleState("topWords", !is.null(input$text) && input$text != "") # these don't work either
# shinyjs::toggleState("topWords", is.null(input$text) || input$text == "")
...
})
})当页面加载时,我试图隐藏顶部单词和按钮,然后在文本区域中输入单词时显示它们。shinyjs::hidden() in ui.R确实隐藏了测试中的顶级单词,但是服务器中的shinyjs::toggleState()没有在文本区域中输入一些文本时显示topwords。
我已经干了几天了,也许这是显而易见的.也许只是添加到shinyjs::toggleState()中的条件
谢谢!
发布于 2018-07-15 19:43:15
我设法弄明白了。我没有在server.R中使用shinyjs::toggleState(),而是将其更改为shinyjs::toggle(),现在我得到了所需的效果。
不过,它似乎改变了预测,只增加了两个单词,而不是一个。
我会继续努力的。
https://stackoverflow.com/questions/51333133
复制相似问题