给定的 R 闪亮脚本在侧边栏中创建一个下拉菜单,其中包含主菜单项和子菜单项。当您单击第一个子项 1 时,您会在 dashboardBody 中获得两个 selectInputs。我想要一个功能,我只需声明这些输入一次并在其他子项中多次使用它,就像反应函数的方式一样。我想这样做以使脚本快速高效。我对反应性功能知之甚少,请帮助和感谢。
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
sidebarMenu(
id = "tabs",
menuItem("Charts", icon = icon("bar-chart-o"),
menuSubItem("Sub-item 1", tabName = "subitem1"),
menuSubItem("Sub-item 2", tabName = "subitem2"),
menuSubItem("Sub-item 3", tabName = "subitem3"),
menuSubItem("Sub-item 4", tabName = "subitem4")
))),
dashboardBody(
tabItems(
tabItem("subitem1", column(2,offset = 0, style='padding:1px;',
selectInput("select1","select1",c("A1","A2","A3"), selected = "A1")),
column(2,offset = 0, style='padding:1px;',
selectInput("select2","select2",c("A3","A4","A5"), selected = "A3"))),
tabItem("subitem2", "Widgets tab content"),
tabItem("subitem3", "Sub-item 1 tab content"),
tabItem("subitem4", "Sub-item 2 tab content"))))
server <- function(input, output, session) {
}
shinyApp(ui, server)