简体   繁体   English

R Shiny 中的 renderUI 不显示

[英]renderUI in R shiny doesn't display

Sometimes we'd like to put content in a uiOutput/renderUI.有时我们想将内容放在 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.在我看来,code#1 和 code#2 应该给我相同的 GUI。 However, code#2 doesn't work as expected.但是,代码#2 没有按预期工作。 Can anyone tell me the reason?谁能告诉我原因? Thanks!谢谢!

Code#1:代码#1:

library(shiny)

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

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

shinyApp(ui = ui, server = server)

Code#2:代码#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)

In the second example, uiOutput wraps the content of navbarMenu inside a div with the class "shiny-html-output" .在第二示例中, uiOutput包装的内容navbarMenu一个div内部与类"shiny-html-output" Divs of this class are however not allowed as an argument for navbarPage .然而, navbarPage不允许作为navbarPage的参数。 AFAIK, there are two ways to resolve this AFAIK,有两种方法可以解决这个问题

The first is to create the whole navbarPage on the server-side.首先是在服务器端创建整个navbarPage

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另一种是只在服务器中创建tabPanel的内容

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)

Please try to set your working directory first like example below.请尝试先设置您的工作目录,如下例所示。

setwd("c:/Users/ID/Desktop/folder") setwd("c:/用户/ID/桌面/文件夹")

You should get working directory with location of ui.R and server.R.你应该得到带有 ui.R 和 server.R 位置的工作目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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