G.Bo
G.Bo

Reputation: 1

renderUI in R shiny doesn't display

Sometimes we'd like to put content in a uiOutput/renderUI. But this doesn't always work. For instance, the example below. In my mind, code#1 and code#2 should give me the same GUI. However, code#2 doesn't work as expected. Can anyone tell me the reason? Thanks!

Code#1:

library(shiny)

ui <- navbarPage("test",
                 navbarMenu("More",
                            tabPanel("Table"
                            )
                 )
)

server <- shinyServer(function(input, output, session) {
})

shinyApp(ui = ui, server = server)

Code#2:

library(shiny)

ui <- navbarPage("test",
           uiOutput("ui_data")
)

server <- shinyServer(function(input, output, session) {

  output$ui_data <- renderUI({
    navbarMenu("More",
               tabPanel("Table"
               )
    )
  })

})

shinyApp(ui = ui, server = server)

Upvotes: 0

Views: 1310

Answers (2)

Tashi
Tashi

Reputation: 19

Please try to set your working directory first like example below.

setwd("c:/Users/ID/Desktop/folder")

You should get working directory with location of ui.R and server.R.

Upvotes: 1

Gregor de Cillia
Gregor de Cillia

Reputation: 7665

In the second example, uiOutput wraps the content of navbarMenu inside a div with the class "shiny-html-output". Divs of this class are however not allowed as an argument for navbarPage. AFAIK, there are two ways to resolve this

The first is to create the whole navbarPage on the server-side.

library(shiny)

ui <- uiOutput("page")

server <- shinyServer(function(input, output, session) {
  output$page <- renderUI({
    navbarPage("test", navbarMenu("More", tabPanel("Table")))
  })
})

shinyApp(ui, server)

The other one is to only create the contents of the tabPanel in the server

library(shiny)

ui <- navbarPage(
  "test", 
  navbarMenu("More", tabPanel("Table", uiOutput("tab_content")))
)

server <- shinyServer(function(input, output, session) {
  output$tab_content <- renderUI({
    "Some content"
  })
})

shinyApp(ui = ui, server = server)

Upvotes: 3

Related Questions