3

我知道有一些关于这个问题的帖子,但我不明白为什么我的代码不起作用。我在 Shiny 中有一个应用程序,我希望它包含一个条件侧边栏面板,它根据用户当前选择的主面板中的哪个面板显示不同的控件。我认为下面的代码可以工作,但该应用程序仅显示条件面板 1(定义如下)。谁能给我任何建议?谢谢。

我的 ui.R:

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"))))
4

1 回答 1

9

看起来 conditionalPanel 语句正在寻找 tabPanel 的名称

 # This will not work
 condition="input.conditionedPanels == 1" #wrong

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

我挖出了所有无关的东西,让你的 UI.R 按预期有条件地工作。您可以以此为起点,从这里开始。

用户界面

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"                
        )
    )  
))
于 2013-10-25T21:42:54.333 回答