R “闪亮”工具栏中的条件面板
我知道有一些关于这个问题的帖子,但我不明白为什么我的代码不起作用。我有一个闪亮的应用程序,我希望它包含一个条件边栏面板,根据用户当前选择的主面板中的哪个面板显示不同的控件。我认为下面的代码可以工作,但应用程序只显示条件面板1(定义如下)。有人能给我一些建议吗?谢谢 我的ui.R:R “闪亮”工具栏中的条件面板,r,shiny,conditional,R,Shiny,Conditional,我知道有一些关于这个问题的帖子,但我不明白为什么我的代码不起作用。我有一个闪亮的应用程序,我希望它包含一个条件边栏面板,根据用户当前选择的主面板中的哪个面板显示不同的控件。我认为下面的代码可以工作,但应用程序只显示条件面板1(定义如下)。有人能给我一些建议吗?谢谢 我的ui.R: library(shiny) shinyUI(pageWithSidebar( # Application title headerPanel("Spatially Balanced Sampling T
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"))))
库(闪亮)
shinyUI(带侧栏的页面)(
#申请名称
headerPanel(“空间平衡采样工具”),
侧栏面板(
标签$head(
标记$style(type=“text/css”,“选择{max width:175px;}”),
标签$style(type=“text/css”,“textarea{max width:100px;}”),
标记$style(type=“text/css”,“.jslider{max width:120px;}”),
标记$style(type='text/css',“.well{max width:200px;}”),
标记$style(type='text/css',“.span4{max width:200px;}”)
),
conditionalPanel(condition=“input.ConditionalPanels==1”,
fileInput('file1','Choose.ZIP Shapefile:',multiple=TRUE,
accept=c('binary'))
),
conditionalPanel(condition=“input.ConditionalPanels==2”,
每层采样点的数值输入(“pts”),“#:”,50),
数值输入(“过采样”,“到过采样(可选):”,5),
submitButton(“生成点”),
帮助文本(“该死的工作”)
)),
主面板(
选项卡面板(
选项卡面板(“说明”,
includeHTML(“instructions.html”),
div(id=“linkToMap”,标记$a(“单击此处查看输入数据的地图并创建点”),
div(id=“linkToPoints”,标记$a(“单击此处查看创建点表”),
值=1
),
选项卡面板(“绘图”,帮助文本(“输入多边形地图”),
绘图输出(“绘图”),
p(粘贴(“按地层排列的多边形”),
值=2
),
选项卡面板(“视点”,帮助文本(“建议采样点”),
tableOutput(“pointdata”),
HTML($('#linkToMap')。单击(函数(){
tabs=$('.tabbable.nav.nav-tabs li')
tabs.each(函数(){
$(this.removeClass('active'))
})
$(制表符[1]).addClass('active')
tabsContents=$('.tabbable.tab内容.tab窗格')
tabsContents.each(函数(){
$(this.removeClass('active'))
})
$(tabsContents[1]).addClass('active')
$('#plot')。触发器('change')。触发器('show'))
})
"),
HTML($('#linkToPoints')。单击(函数(){
tabs=$('.tabbable.nav.nav-tabs li')
tabs.each(函数(){
$(this.removeClass('active'))
})
$(制表符[2]).addClass('active')
tabsContents=$('.tabbable.tab内容.tab窗格')
tabsContents.each(函数(){
$(this.removeClass('active'))
})
$(tabsContents[2]).addClass('active')
$('#pointdata')。触发器('change')。触发器('Showed'))
})
"),
值=2
),
id=“conditionedPanels”))
看起来conditionalPanel语句正在查找选项卡面板的名称
# This will not work
condition="input.conditionedPanels == 1" #wrong
当我在conditionalPanel
语句中切换条件以测试选项卡的名称而不是值时,它起了作用
我挖出了所有无关的东西,让您的UI.R按预期有条件地工作。你可以从这里开始
用户界面
谢谢你,拉姆。。但这与我看到的文档不符?然而,我确实尝试了你的建议,我仍然得到了和以前一样的错误行为。我怀疑现在我的代码的其他部分带来了某种bug。我有一个更简单的应用程序,我可以让条件侧栏与我的原始帖子的语法/格式一起工作。文档确实说条件面板将计算JavaScript表达式。你是对的,文档可能会更清晰,但与此同时,闪亮的谷歌团队非常棒。是的,我怀疑代码其余部分中的其他行导致它无法工作。我注意到在任一条件面板中添加submitButton()将中断交互。例如:conditionalPanel(condition=“input.ConditionalPanels==“Tab1”),helpText(“Tab1”),submitButton(),
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"
)
)
))