【问题标题】:Show/Hide button on tab select R shiny选项卡上的显示/隐藏按钮选择 R 闪亮
【发布时间】:2017-01-19 19:41:10
【问题描述】:

我的 ui.R 中有一个按钮,我只想在选择“摘要”选项卡时显示,所以我想到了这段代码

 fluidRow(
  column(4, 
   column(12,id="sub",
       actionButton("submit", "SUBMIT", width = "100%"))),
  column(8,
   bsCollapse(id = "collapse7", open = "Results",
       bsCollapsePanel("Results",
         tabsetPanel(
          tabPanel("Summary",
            tags$script(HTML("document.getElementById('sub').style.visibility = 'visible';")))
          tabPanel("Plot",
            tags$script(HTML("document.getElementById('sub').style.visibility = 'hidden';"))))
        ))))

问题是,按钮是隐藏的,即使在我的第一个选项卡中它应该是可见的,而且当我转到 Plots 并返回 Summary 时,按钮仍然隐藏。

【问题讨论】:

  • 看看院长shinyjs 包。 deanattali.com/2015/04/23/shinyjs-r-package
  • @PorkChop 链接,我检查了一下,发现了很多有用的东西。在我设法在下面自己解决之后,我发布了我的问题的解决方案。感谢您的信息。

标签: r shiny


【解决方案1】:

看完后:How to use tabPanel as input in R Shiny?

我决定使用 observeEvent 和 input$tabset 选项。结果是 100% 有效,而且非常简单。代码如下:

observeEvent(input$choices, {
 choice = input$choices
 if(choice == "Summary")
 {
  runjs(
    "document.getElementById('submit').style.visibility = 'visible';"
  )
 }
 else
 {
  runjs(
    "document.getElementById('submit').style.visibility = 'hidden';"
  )
 }
})

另外,我发现了为什么我之前的代码不起作用,这是因为当 UI 初始化时,按钮元素保留了最后的样式修改(隐藏的那个)并且它没有改变在我选择的标签上,因为它不是反应式的。

【讨论】:

  • 谢谢!如果我知道 runjs 是什么,这会更有用,但我现在将研究 shinyjs 项目。
猜你喜欢
  • 1970-01-01
  • 2018-10-17
  • 2017-02-20
  • 1970-01-01
  • 1970-01-01
  • 2013-02-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多