我使用多个选项卡构建了R Shiny应用程序,其中有一些共同的过滤器。现在,所有过滤器都是独立的,不会跨多个选项卡进行同步。因此,当我将selectInput1从值“a”更改为值“b”时,我必须在包含selectInput2的下一个选项卡上以相同的选项/含义重复此处理。R在多个选项卡上闪亮的同步过滤器
我考虑过滤器是动态的,因此使用R Shiny的服务器端渲染它们。那么当然,我总是可以使selectInput2等于selectInput1。但是如果用户改变了selectInput2而不是selectInput1呢?它在逻辑中创建了一种循环。
我花了一段时间找到解决这个问题的方法,不知何故,我确信我不是第一个遇到这个问题的人。建议或有用的链接将非常有帮助!
实施例:
## UI.R
shinyUI(
dashboardPage("Dashboard",
# Create tabs
tabPanel("Start",
p("This is the frontpage")
),
tabPanel("tab1",
uiOutput("selectInput1")
),
tabPanel("tab2",
uiOutput("selectInput2")
)
)
)
和:
## Server.R
library(shiny)
shinyServer(function(input, output,session){
output$selectInput1 <- renderUI({
selectInput(inputId = "id1",
label = "select",
choices = c("a","b","c"),
selected = "a")
})
output$selectInput2 <- renderUI({
selectInput(inputId = "id2",
label = "select",
choices = c("a","b","c"),
selected = "a")
})
})
在侧边栏中添加一个selectInput有什么问题?这就是我要做的事情,因为您希望用户在所有选项卡上进行单一选择。 –
谢谢你的快速回复。在两个选项卡上添加相同的selectInput元素不起作用,因为Shiny需要为每个加载的元素添加不同的ID。当我尝试使用renderUI(Server)和uiOutput(UI)加载两个相同的元素时,它无法加载任何元素。 – Dendrobates
sry,那是'renderUI()'错误。但是,如果你使用侧边栏,你不必包含它两次,就像@JorisMeys说的那样。如果没有,最好给我们举个例子,... – BigDataScientist