首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >发亮边栏中的条件面板

发亮边栏中的条件面板
EN

Stack Overflow用户
提问于 2013-10-25 00:25:52
回答 1查看 12.3K关注 0票数 3

我知道有一些关于这个问题的文章,但是我不明白为什么我的代码不能工作。我有一个闪亮的应用程序,我想要包含一个条件侧栏面板,它显示了不同的控件,在主面板中的哪个面板目前是由用户选择的。我认为下面的代码可以工作,但应用程序只显示条件面板1(如下所示)。有人能给我提点建议吗?谢谢。

我的ui.R:

代码语言:javascript
运行
复制
library(shiny)


shinyUI(pageWithSidebar(

  # Application title
  headerPanel("Spatially Balanced Sampling Tool"),

  sidebarPanel(
    tags$head(
      tags$style(type="text/css", "select { max-width: 175px; }"),
      tags$style(type="text/css", "textarea { max-width: 100px; }"),
      tags$style(type="text/css", ".jslider { max-width: 120px; }"),
      tags$style(type='text/css', ".well { max-width: 200px; }"),
      tags$style(type='text/css', ".span4 { max-width: 200px; }")
    ),

conditionalPanel(condition="input.conditionedPanels == 1",       
                 fileInput('file1', 'Choose .ZIP Shapefile:', multiple=TRUE,
                           accept=c('binary'))
),

conditionalPanel(condition="input.conditionedPanels == 2", 
                   numericInput("pts", "# of sampling points per stratum:", 50),
                   numericInput("oversamppts", "# to OVER sample (optional):", 5),
                   submitButton("Generate Points"),
                 helpText("WORK DAMMIT")

)),

mainPanel(

tabsetPanel(

  tabPanel("Instructions",
           includeHTML("instructions.html"), 
           div(id="linkToMap", tags$a("Click here to see a map of your input data and create points")), 
           div(id="linkToPoints", tags$a("Click here to see table of created points")),
           value=1
  ),

  tabPanel("plot",  helpText("Map of input polygons"),
           plotOutput("plot"),
           p(paste("polygons by strata")),

           value=2
  ),
  tabPanel("View Points", helpText("suggested sampling points"),
           tableOutput("pointdata"),


           HTML("<script>$('#linkToMap').click(function() {
                tabs = $('.tabbable .nav.nav-tabs li')
                tabs.each(function() {
                $(this).removeClass('active')
                })
                $(tabs[1]).addClass('active')
                tabsContents = $('.tabbable .tab-content .tab-pane')
                tabsContents.each(function() {
                $(this).removeClass('active')
                })
                $(tabsContents[1]).addClass('active')

                $('#plot').trigger('change').trigger('shown')

                })</script>
                "),
           HTML("<script>$('#linkToPoints').click(function() {
                tabs = $('.tabbable .nav.nav-tabs li')
                tabs.each(function() {
                $(this).removeClass('active')
                })
                $(tabs[2]).addClass('active')
                tabsContents = $('.tabbable .tab-content .tab-pane')
                tabsContents.each(function() {
                $(this).removeClass('active')
                })
                $(tabsContents[2]).addClass('active')

                $('#pointdata').trigger('change').trigger('shown')

           })</script>
                "),
           value=2
           ),


id = "conditionedPanels"))))
EN

Stack Overflow用户

发布于 2013-10-25 21:42:54

看起来,conditionalPanel语句正在查找tabPanel的名称。

代码语言:javascript
运行
复制
 # This will not work
 condition="input.conditionedPanels == 1" #wrong

当我切换conditionalPanel语句中的条件以测试选项卡的名称(而不是值)时,它起了作用。

我把所有无关的东西都挖出来,让你的UI.R按计划有条件地工作。你可以用这个作为起点,然后从这里开始。

UI.R

代码语言:javascript
运行
复制
library(shiny)
shinyUI(pageWithSidebar(  
  headerPanel("Spatially Balanced Sampling Tool"),
  sidebarPanel(
    conditionalPanel(condition="input.conditionedPanels == 'Tab1'",       
                     helpText("TAB 1")
    ),    
    conditionalPanel(condition="input.conditionedPanels == 'Tab2'", 
                     helpText("TAB 2 SELECTED")
                    )
    ),
  
  mainPanel(
    tabsetPanel(
      tabPanel("Tab1",
               p(paste("Tab 1 text")                 
          )
      ),
      tabPanel("Tab2",  helpText("Map of input polygons"),
               p(paste("polygons by strata")
                 )
      ), 
      id = "conditionedPanels"                
        )
    )  
))
票数 9
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19579067

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档