Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 使用shinyjs隐藏/显示ui元素_R_Shiny_Shinyjs - Fatal编程技术网

R 使用shinyjs隐藏/显示ui元素

R 使用shinyjs隐藏/显示ui元素,r,shiny,shinyjs,R,Shiny,Shinyjs,我一直在开发一款闪亮的应用程序,它运行正常(请参阅) 以下是相关代码: # ui.R library(shiny) library(shinyjs) shinyUI(fluidPage( useShinyjs(), # Set up shinyjs titlePanel("Next Word PredictR"), sidebarLayout( sidebarPanel("Top Next Words", br(" "),

我一直在开发一款闪亮的应用程序,它运行正常(请参阅)

以下是相关代码:

    # 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&#8217;s postmaster, told ... <strong>me.</strong>'),
          HTML('<br /><br />&quot;The Voice,&quot; NBC&#8217;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. &#9786;')
        )
      )
      )
    )
    # 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 == "")
    ...

       })
    })
#ui.R
图书馆(闪亮)
图书馆(shinyjs)
shinyUI(fluidPage)(
使用shinyjs(),#设置shinyjs
titlePanel(“下一个单词预测器”),
侧边栏布局(
侧边栏面板(“最上面的下一个单词”,
br(“”),
shinyjs::hidden#这会隐藏topWords,但server.R中的toggleState不会切换!?!
(
tableOutput('topWords')
)
),
主面板(“在下面的框中输入单词或单击一个按钮,#这很有效
br(“”),
标签$head(
标签$style(HTML(“
#按钮1、#按钮2、#按钮3、#按钮4
{
颜色:#FFFFFF;
字体大小:粗体;
背景色:#00AEAE;
边框颜色:#FFFFFF;
}
#正文
{
宽度:82%;
}
"))
),
标签$div(
标记$textarea(id='text',label='在下面的框中输入单词或单击按钮',rows=2,class='form-control',''),#标签不起作用
br(“”),
htmlOutput(“第一个字”,内联=T),
htmlOutput(“第二个字”,内联=T),
htmlOutput(“第三个字”,内联=T),
htmlOutput(“四向”,内联=T),
br(“”),
p('以下是从英语新闻语料库中提取的五个句子,您可以复制/粘贴到上面的框中。提示:不要复制/粘贴省略号(…)或下一个单词(粗体)。',
HTML(“又一个月的强劲招聘使得美联储在下周的会议上采取进一步措施提振经济的可能性降低了。),
HTML(“

当Junior周日走进追悼会时,“这对每个人来说都是一个惊喜,”Oceanside&8217;的邮政局长道格·史密斯告诉……我。”, HTML(“

”美国全国广播公司(NBC’;的新贵歌唱比赛“The Voice”于周日回归第二季,该电视台正以黄金时间的方式将其开播——将其定位在超级……碗赛之后。”), HTML(“

导致迈耶辞职的主要健康问题是他留下的一个终生病假计划…支持。”), HTML(“

斯佳丽·约翰逊拍摄了阿什兰路靠近朗费罗大道的一个旧仓库的场景,雪松路附近靠近诺福克南部铁路……轨道。”), HTML(“

免责声明:是的,我当然选择了这些句子。我测试的绝大多数句子都失败得很惨。” ) ) ) ) #服务器.R 图书馆(闪亮) 图书馆(shinyjs) 图书馆(tm) 图书馆(qdap) 图书馆(dplyr)
我设法弄明白了。我没有在server.R中使用shinyjs::toggleState(),而是将其改为仅使用shinyjs::toggle(),现在我得到了所需的效果

不过,这似乎改变了预测,增加了两个词,而不是一个词


我会继续努力的。

看来闪亮社区在投票方面有点吝啬。我通常会在零票的情况下找到好东西。我高兴得太早了吗?切换和切换状态是非常不同的功能。请查看他们的文档-toggle用于显示/隐藏,toggleState用于启用/禁用