R闪亮:conditionalPanel在选定面板上共享边栏
R Shiny: conditionalPanel sharing sidebars on select panels
我正在尝试在不同的面板上显示反应图。其中一些是基于相同的输入,这些输入来自侧边栏上的滑块。我想在这些面板之间保留相同的滑块(和输入)。在其他面板中,我想要唯一的条件输入。这里有一个例子:
##server
shinyServer(function(input, output) {
output$scatterPlotA <- renderPlot({
x <- rnorm(input$slider1)
y <- rnorm(input$slider1)
plot(x, y)
})
output$scatterPlotB <- renderPlot({
x <- rnorm(input$slider2)
y <- rnorm(input$slider2)
plot(x, y)
})
output$scatterPlotC <- renderPlot({
x <- rnorm(input$slider2)
y <- rnorm(input$slider2)
plot(x, y,col="red")
})
})
这个ui保存了面板2-3之间的滑块,但它不会控制3。
##ui
shinyUI(pageWithSidebar(
headerPanel("Conditional Panels"),
sidebarPanel(
conditionalPanel(condition="input.conditionedPanels==1",
helpText("Content Panel 1"),
sliderInput("slider1", "Number of points: S1", min = 10, max = 200, value = 50, step = 10)
),
conditionalPanel(condition="input.conditionedPanels==2",
helpText("Content Panel 2"),
sliderInput("slider2", "Number of points: S2", min = 10, max = 200, value = 50, step = 10)
),
conditionalPanel(condition="input.conditionedPanels==3",
helpText("Content Panel 2"),
sliderInput("slider2", "Number of points: S2", min = 10, max = 200, value = 50, step = 10)
)
),
mainPanel(
tabsetPanel(
tabPanel("Panel 1", value=1,
plotOutput("scatterPlotA", height = 300)),
tabPanel("Panel 2", value=2,
plotOutput("scatterPlotB", height = 300)),
tabPanel("Panel 3", value=3,
plotOutput("scatterPlotC", height = 300)),
id = "conditionedPanels"
)
)
))
这个ui做我想要的事情,除了面板2的滑块最终出现在面板1上。
##ui
shinyUI(pageWithSidebar(
headerPanel("Conditional Panels"),
sidebarPanel(
conditionalPanel(condition="input.conditionedPanels==1",
helpText("Content Panel 1"),
sliderInput("slider1", "Number of points: S1", min = 10, max = 200, value = 50, step = 10)
),
conditionalPanel(condition="input.conditionedPanels==2||3",
helpText("Content Panel 2"),
sliderInput("slider2", "Number of points: S2", min = 10, max = 200, value = 50, step = 10)
)
),
mainPanel(
tabsetPanel(
tabPanel("Panel 1", value=1,
plotOutput("scatterPlotA", height = 300)),
tabPanel("Panel 2", value=2,
plotOutput("scatterPlotB", height = 300)),
tabPanel("Panel 3", value=3,
plotOutput("scatterPlotC", height = 300)),
id = "conditionedPanels"
)
)
))
在面板之间共享一些边栏,同时使其他边栏变得独特,有什么指导吗?
第一个ui.R
的问题是您仍然定义了三个不同的滑块。您真正想要的是第二个滑块出现在两种情况中的任何一种情况下。因此,更改第二个滑块的条件以反映该逻辑,并去掉第三个滑块。以下代码对我有效。
sidebarPanel(
conditionalPanel(condition="input.conditionedPanels==1",
helpText("Content Panel 1"),
sliderInput("slider1", "Number of points: S1", min = 10, max = 200, value = 50, step = 10)
),
conditionalPanel(condition="input.conditionedPanels==2 || input.conditionedPanels==3",
helpText("Content Panel 2"),
sliderInput("slider2", "Number of points: S2", min = 10, max = 200, value = 50, step = 10)
)
),
相关文章:
- Facebook共享显示一个接一个的空白页面
- 通过javascript/html访问twitter共享iframe
- 在我的SPA应用程序中集成Facebook共享的问题
- 在索引.html和应用.js [node.js] 之间共享变量
- AngularJS:$q.dedefe()不能由工厂方法共享
- 使用闭包共享构造函数参数
- Facebook共享动态参数链接
- Node.js上的WebSocket,并在所有连接的客户端之间共享消息
- 如何在没有插件和Wordpress的情况下创建共享社交媒体
- 在requirejs中共享实例化对象
- 在Javascript服务器/客户端中共享对象定义
- 使用服务(AngularJS)在控制器之间共享数据
- 我可以共享一个HTML播放器吗
- AngularJS中的页面之间共享数据返回空
- 如何在批准露天共享中工作流的审核步骤之前添加确认对话框
- 是否可以缓存可下载的文件,并在XHR和非XHR请求之间共享该缓存
- Facebook共享链接适用于用户,但不适用于粉丝页面管理员
- Facebook共享在2016年不起作用
- 在Knockoutjs中的ViewModels之间共享变量状态
- R闪亮:conditionalPanel在选定面板上共享边栏