简体   繁体   中英

Call dashboard page from server in shiny

I am trying to call dashboardPage from a function in server in Shiny. It is not showing the dahsboard page but showing a blank page. How do I redirect it to my dashboardPage. Currently it is showing a blank page to me after redirecting. Following is the code:

## app.R ##
library(shinydashboard)
library(shiny)
library(shinythemes)
library(DT)
ui1 <- function(){}

ui2 <- dashboardPage(){}

ui = (uiOutput("page"))

server <- function(input, output, session) {
if (USER$Logged == TRUE) 
    {
      output$page <- renderUI({
         ui2() 
      ###Here is the problem. It is not redirecting to ui2 which is
      ###a dashboardPage.
      })
    }
}

You didn't implement dashboardPage function properly. Below code would give you an idea how to work with it.

library(shinydashboard)
library(shiny)
library(shinythemes)
library(DT)

header <- dashboardHeader(
  title = "dynamicDates",
  tags$li(class = "dropdown", tags$a(HTML(paste(uiOutput("Refresh1"))))))
body <- dashboardBody("this is body function", 
                      uiOutput("page"))
sidebar <- dashboardSidebar("this is side bar")
#we must pass header,body and sidebar parameters in dashboardPage funtion, which you have missed to specify. 
ui <- dashboardPage(header, sidebar, body, title = "example") 

server <- function(input, output, session) {
  output$Refresh1 <- renderText({
    toString(format(Sys.Date(), format = "%A  %d %b %Y"))
  })
  output$page <- renderUI("shiny dashboard")
}

shinyApp(ui, server)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM