我试图在不同的面板上显示反应图。其中一些是基于相同的输入,来自侧栏上的滑块。我想在这些面板之间保留相同的滑块(和输入)。在其他面板中,我想要独特的条件输入。这是一个例子:
##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"
)
)
))
任何有关在面板之间共享一些侧边栏同时使其他人独特的指南?
答案 0 :(得分:1)
您的第一个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)
)
),