Shinydashboard 侧边栏初学者问题——要点
Shinydashboard Sidebar Beginner Question -- Bulletpoints
到目前为止,我的第一个 shinydashboard 应用程序看起来不错,除了侧边栏中的要点。我做错了什么?
ui <- shinydashboard::dashboardPage(
shinydashboard::dashboardHeader(title="First App"),
shinydashboard::dashboardSidebar(
shinydashboard::menuItem("Accounts", tabName = "accounts", icon = shiny::icon("users")),
shinydashboard::menuItem("Topics", icon = shiny::icon("hashtag"),
shinydashboard::menuSubItem("Multi-Topic-View", tabName = "topics_multi"),
shinydashboard::menuSubItem("Single-Topic-View", tabName = "topic_single"),
shinydashboard::menuSubItem("Tweet-View", tabName = "topic_tweet")
)
),
shinydashboard::dashboardBody(
shinydashboard::tabItems(
shinydashboard::tabItem(tabName="accounts", shiny::h2("Account tab content")),
shinydashboard::tabItem(tabName="topics_multi", shiny::h2("Multi Topic tab content")),
shinydashboard::tabItem(tabName="topic_single", shiny::h2("Single Topic tab content")),
shinydashboard::tabItem(tabName="topic_tweet", shiny::h2("Tweet Topic tab content"))
)
)
)
server <- function(input, output) { }
app <- shiny::shinyApp(ui, server)
shiny::runApp(app, launch.browser=TRUE)
这是我在 Windows 机器(R 版本 4.0.3,shinydashboard_0 上 Google Chrome 中 运行 这段代码的截图。 7.1,shiny_1.6.0)。我可以去掉要点吗?
在dashboardSidebar()
中使用sidebarMenu(id = "tabs",...)
来消除要点。您可以根据需要定义 id
。
ui <- shinydashboard::dashboardPage(
shinydashboard::dashboardHeader(title="First App"),
dashboardSidebar(
sidebarMenu(id = "tabs", # Setting id makes input$tabs give the tabName of currently-selected tab
menuItem("Accounts", tabName = "accounts", icon = icon("users")),
menuItem("Topics", icon = shiny::icon("hashtag"),
menuSubItem("Multi-Topic-View", tabName = "topics_multi"),
menuSubItem("Single-Topic-View", tabName = "topic_single"),
menuSubItem("Tweet-View", tabName = "topic_tweet")
))
),
shinydashboard::dashboardBody(
tabItems(
tabItem(tabName="accounts", shiny::h2("Account tab content")),
tabItem(tabName="topics_multi", shiny::h2("Multi Topic tab content")),
tabItem(tabName="topic_single", shiny::h2("Single Topic tab content")),
tabItem(tabName="topic_tweet", shiny::h2("Tweet Topic tab content"))
)
)
)
server <- function(input, output, session) { }
shinyApp(ui, server)
到目前为止,我的第一个 shinydashboard 应用程序看起来不错,除了侧边栏中的要点。我做错了什么?
ui <- shinydashboard::dashboardPage(
shinydashboard::dashboardHeader(title="First App"),
shinydashboard::dashboardSidebar(
shinydashboard::menuItem("Accounts", tabName = "accounts", icon = shiny::icon("users")),
shinydashboard::menuItem("Topics", icon = shiny::icon("hashtag"),
shinydashboard::menuSubItem("Multi-Topic-View", tabName = "topics_multi"),
shinydashboard::menuSubItem("Single-Topic-View", tabName = "topic_single"),
shinydashboard::menuSubItem("Tweet-View", tabName = "topic_tweet")
)
),
shinydashboard::dashboardBody(
shinydashboard::tabItems(
shinydashboard::tabItem(tabName="accounts", shiny::h2("Account tab content")),
shinydashboard::tabItem(tabName="topics_multi", shiny::h2("Multi Topic tab content")),
shinydashboard::tabItem(tabName="topic_single", shiny::h2("Single Topic tab content")),
shinydashboard::tabItem(tabName="topic_tweet", shiny::h2("Tweet Topic tab content"))
)
)
)
server <- function(input, output) { }
app <- shiny::shinyApp(ui, server)
shiny::runApp(app, launch.browser=TRUE)
这是我在 Windows 机器(R 版本 4.0.3,shinydashboard_0 上 Google Chrome 中 运行 这段代码的截图。 7.1,shiny_1.6.0)。我可以去掉要点吗?
在dashboardSidebar()
中使用sidebarMenu(id = "tabs",...)
来消除要点。您可以根据需要定义 id
。
ui <- shinydashboard::dashboardPage(
shinydashboard::dashboardHeader(title="First App"),
dashboardSidebar(
sidebarMenu(id = "tabs", # Setting id makes input$tabs give the tabName of currently-selected tab
menuItem("Accounts", tabName = "accounts", icon = icon("users")),
menuItem("Topics", icon = shiny::icon("hashtag"),
menuSubItem("Multi-Topic-View", tabName = "topics_multi"),
menuSubItem("Single-Topic-View", tabName = "topic_single"),
menuSubItem("Tweet-View", tabName = "topic_tweet")
))
),
shinydashboard::dashboardBody(
tabItems(
tabItem(tabName="accounts", shiny::h2("Account tab content")),
tabItem(tabName="topics_multi", shiny::h2("Multi Topic tab content")),
tabItem(tabName="topic_single", shiny::h2("Single Topic tab content")),
tabItem(tabName="topic_tweet", shiny::h2("Tweet Topic tab content"))
)
)
)
server <- function(input, output, session) { }
shinyApp(ui, server)