【发布时间】:2017-10-07 13:00:42
【问题描述】:
我想在选项卡式闪亮应用中重复使用输入字段。我的代码如下。
library(shiny)
ui <- navbarPage("Iris data browser",
tabPanel("Panel 1",
selectInput("species", "Species",
unique(iris$Species)),
sliderInput("sepal.length", "Sepal length",
4.3,7.9,4.5,.1),
tableOutput("table1")),
tabPanel("Panel 2",
selectInput("species", "Species",
unique(iris$Species)),
tableOutput("table2")))
server <- function(input, output) {
output$table1 <- renderTable({
iris[iris$Species == input$species & iris$Sepal.Length <= input$sepal.length,c("Sepal.Length","Sepal.Width")]
})
output$table2 <- renderTable({
iris[iris$Species == input$species,c("Petal.Length","Petal.Width")]
})
}
# Run the application
shinyApp(ui = ui, server = server)
我想在两个面板上使用相同的selectInput()。预期的结果是,当我更改“面板 1”中的输入值时,它将在“面板 2”中采用相同的值,反之亦然。当然,过滤也应该应用于两个面板上的表格。此外,物种的输入在两个面板上共享,但萼片长度的滑块应该只出现在面板 1 上。因此,sidebarLayout() 不是解决方案。
谢谢!
【问题讨论】:
-
会出现在多个面板还是全部?
-
不,可能有第三个选项卡没有 selectInput()
-
也许一个闪亮的模块就是答案。看了文档和 rstudio 的文章,但我无法理解它......
-
使用
sidebarPanel并将selectInput放在旁边,在tabPanels 之外。 -
@zx8754 这不起作用,因为我希望可以选择在各个选项卡上具有不同的输入,并且只有一些在选项卡之间共享。我会更新上面的代码。我在面板 1 上添加了额外的代码,并在面板 2 上没有出现的额外用户输入字段(sliderInput())