Reputation: 23
I have made a shiny app and I cant figure out how to add a front page to it. There are currently 2 side bar menu options, one is a link and other one has subitems in it that displays two different tabs. But as soon as i open the app, it shows by default page in tab1.
I'd like to know if I can instead add another page, not related to sidebar so it shows as first and only after selecting an option from tab1 or tab2 will there be any plots. Can anyone offer a solution to this ?
ie. Without ">>" tab, indicating that front page has been made as a separate tab.
library(shiny)
library(shinydashboard)
library(dygraphs)
library(ggplot2)
ui <- dashboardPage(dashboardHeader(title="Test Page"),
dashboardSidebar(id="",sidebarMenu(
menuItem(menuSubItem("",tabName = "STO")),
menuItem(text="Visit-us", icon = icon("send",lib='glyphicon'), href = "https://www.google.com"),
menuItem(text="Tab1",icon=icon("line-chart"),
menuSubItem("Sub-Tab1",tabName = "ST1"),
menuSubItem("Sub-Tab2",tabName = "ST2")))),
dashboardBody(
tabItems(
tabItem(tabName = "STO",verbatimTextOutput("welcome")),
tabItem(tabName = "ST1",dygraphOutput("plot1"),br(),plotOutput("plot2")),
tabItem(tabName = "ST2",dygraphOutput("dt")))))
server <- function(input, output, session) {
output$welcome <- renderText({
"Welcome to my shiny application. Here we can use and visualize various..." })
output$plot1 <- renderDygraph({
lungDeaths <- cbind(ldeaths, mdeaths, fdeaths)
dygraph(lungDeaths, main = "Deaths from Lung Disease (UK)") %>%
dyOptions(colors = RColorBrewer::brewer.pal(3, "Set2"))})
output$plot2 <-renderPlot({
hist(lungDeaths)})
output$dt <- renderDygraph({
dygraph(lungDeaths, main = "Deaths from Lung Disease (UK)") %>%
dyOptions(stepPlot = TRUE) })}
shinyApp(ui, server)
Upvotes: 2
Views: 2246
Reputation: 2864
shinydashboard
is designed for you to navigate across sidebar items. You can always customize your shiny
application but this will require some knowledge of the framework. I suggest having a 'home page':
# replace "menuItem(menuSubItem("",tabName = "STO"))," with the following
menuItem("Home", tabName = "STO", selected = T),
This will be more flexible compared to a disconnected starting page. You can include your introduction in the home page and users can always come back to read it.
Upvotes: 1