Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用renderUI时,使侧边栏选项卡在默认情况下处于选中状态_R_Shiny_Shinydashboard - Fatal编程技术网

使用renderUI时,使侧边栏选项卡在默认情况下处于选中状态

使用renderUI时,使侧边栏选项卡在默认情况下处于选中状态,r,shiny,shinydashboard,R,Shiny,Shinydashboard,我第一次使用renderUI。当我运行应用程序时,默认情况下没有选择任何选项卡;在服务器外部定义UI时,默认情况下通常选择第一个选项卡 知道为什么会发生这种情况,或者如何指定在启动时默认选择第一个选项卡 例如: library(shiny) library(shinydashboard) library(tidyverse) library(DT) header <- dashboardHeader(title = "header") sidebar <- dashboard

我第一次使用renderUI。当我运行应用程序时,默认情况下没有选择任何选项卡;在服务器外部定义UI时,默认情况下通常选择第一个选项卡

知道为什么会发生这种情况,或者如何指定在启动时默认选择第一个选项卡

例如:

library(shiny)
library(shinydashboard)
library(tidyverse)
library(DT)


header <- dashboardHeader(title = "header") 

sidebar <- dashboardSidebar(uiOutput("sidebar"))

body <- dashboardBody(uiOutput("body"))

ui <- dashboardPage(title = 'Radial Networks', header, sidebar, body, skin='blue')

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

  output$body <- renderUI({
    dashboardBody(
       tabItems(
         tabItem(
           tabName = 'Chords', h2(fluidRow(
             box(plotOutput('plot'), type = 'html',  width = 6, height = '870px')
           )))))})

 output$sidebar <- renderUI({
   dashboardSidebar(sidebarMenu(
     menuItem("Radial Networks", tabName = "Chords", icon = icon("adjust"))))
 })

  output$plot <- renderPlot({
    ggplot(mtcars, aes(x = factor(cyl))) +
      geom_bar()
  })

}

  shinyApp(ui = ui, server = server)
库(闪亮)
图书馆(shinydashboard)
图书馆(tidyverse)
图书馆(DT)

header尝试向tabItem()添加一个参数:

库(闪亮)
图书馆(shinydashboard)
图书馆(tidyverse)
图书馆(DT)

这可能是因为我把你放错位置了。道歉。它需要在侧栏调用中。我在上面编辑过。这仍然不起作用,尽管根据本页:它应该。我还尝试了“selected=TRUE”,但也没有效果。这在这里也是一个令人困惑的问题,选择似乎并不有效。
library(shiny)
library(shinydashboard)
library(tidyverse)
library(DT)


header <- dashboardHeader(title = "header") 

sidebar <- dashboardSidebar(uiOutput("sidebar"))

body <- dashboardBody(uiOutput("body"))

ui <- dashboardPage(title = 'Radial Networks', header, sidebar, body, skin='blue')

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

  output$body <- renderUI({
    dashboardBody(
       tabItems(
         tabItem(
           tabName = 'Chords', 
                        h2(fluidRow(box(plotOutput('plot'), 
                        type = 'html',  
                        width = 6, 
                        height = '870px')
           )))))})

 output$sidebar <- renderUI({
   dashboardSidebar(sidebarMenu(
               menuItem("Radial Networks", 
                     tabName = "Chords", 
                     icon = icon("adjust"),
                     selected = 1)))
 })

  output$plot <- renderPlot({
    ggplot(mtcars, aes(x = factor(cyl))) +
      geom_bar()
  })

}

  shinyApp(ui = ui, server = server)