[英]How to add the same inputs into two tabItems in shinydashboard?
I am using shinydashboard to create the interface of my shiny App.我正在使用 Shinydashboard 来创建我的闪亮应用程序的界面。 However I want one input which appear in the two tabMenu.
但是我想要一个出现在两个 tabMenu 中的输入。 In the example below, I want to
textInput
i_test
appears in menu menu1
and menu2
.在下面的示例中,我希望
textInput
i_test
出现在菜单menu1
和menu2
。
How should I implement it?我应该如何实施它? Thanks for any suggestions.
感谢您的任何建议。
library(shiny)
library(shinydashboard)
# Side bar boardy
sidebar <- dashboardSidebar(
sidebarMenu(
id = 'menu_tabs'
, menuItem('menu1', tabName = 'menu1')
, menuItem('menu2', tabName = 'menu2')
, menuItem('menu3', tabName = 'menu3')
)
)
# Body board
body <- dashboardBody(
tabItems(
tabItem(
tabName = 'menu1',
textInput('i_test', 'Test')
),
tabItem(
tabName = 'menu2'
)
)
)
# Shiny UI
ui <- dashboardPage(
title = 'test',
dashboardHeader(),
sidebar,
body
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
It seems that shiny always renders two distinct elements, even if you try to build the same element a second time.即使您尝试第二次构建相同的元素,shiny 似乎总是呈现两个不同的元素。
Thats why i could only come up with a solution that only makes it look like the two text iputs are the same.这就是为什么我只能想出一个解决方案,它只会让它看起来两个文本输入是相同的。
Check the Code:检查代码:
library(shiny)
library(shinydashboard)
# Side bar boardy
sidebar <- dashboardSidebar(
sidebarMenu(
id = 'menu_tabs'
, menuItem('menu1', tabName = 'menu1')
, menuItem('menu2', tabName = 'menu2')
, menuItem('menu3', tabName = 'menu3')
)
)
# Body board
body <- dashboardBody(
tabItems(
tabItem(
tabName = 'menu1',
textInput('i_test_1', 'Test')
),
tabItem(
tabName = 'menu2',
textInput('i_test_2', 'Test')
),
tabItem(
tabName = 'menu3'
)
)
)
# Shiny UI
ui <- dashboardPage(
title = 'test',
dashboardHeader(),
sidebar,
body
)
server <- function(input, output, session) {
observe({
text1 <- input$i_test_1
updateTextInput(session, 'i_test_2', value = text1)
})
observe({
text2 <- input$i_test_2
updateTextInput(session, 'i_test_1', value = text2)
})
}
shinyApp(ui, server)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.