标签名称未显示

时间:2015-08-31 15:27:59

标签: r shiny

我正在尝试使用shinydashboard在2个不同的选项卡上显示内容,所以我使用tabItems来放置2个tabItem,但是当我运行应用程序时我没有看到选项卡。知道怎么看标签吗?

还有办法将侧边栏控件连接到标签吗?例如,我在Tab1和tab2下面有2个选项卡。当你在标签1上时,是否可以只显示带有TabName = Tab1的侧边栏项?

以下是您可以运行的代码:

server.r

function(input, output,session) {

  output$Text<-renderUI({
#     if(is.null(input$Symbol) == FALSE)
#     {
     # browser()
      rows = length(ReactiveData())
      if(rows ==1 )
      { dat=c("a","")

      }else{
        dat=c("a","b","")
      }
      selectInput("Text", "select text:", c(dat,""),selected = "", multiple = TRUE)
#     }
  })

  ReactiveData<- reactive({

    return(rnorm((as.numeric(input$t)*as.numeric(input$b))))
  })


# output$plot1 <- renderPlot({
#   print("in plot 1")
#   plot(ReactiveData(),type='p', main = input$t)
# })

Reactivet<- reactive({
  return(as.numeric(input$t))
})

output$plot1 <- renderPlot({
  print("in plot 1")
  plot(ReactiveData(),type='p', main = Reactivet())
})



output$plot2<- renderPlot({
  print("in plot 2")
  plot(c(as.numeric(input$t)),type='b')
})

output$plot3<- renderPlot({
  print("in plot 3")
  plot(  as.numeric(input$Plot3Input),type='b')
})

  output$downloadData <- downloadHandler(

    filename = function() { 
      paste("test", '.csv', sep='') 
    },
    content = function(file) {
      write.csv(c(1,2,3,4), file)
    }
  )



}

ui.r

library(shinydashboard)


dashboardPage(skin="black",
  dashboardHeader(title = "Basic dashboard"),
  dashboardSidebar(
    sidebarMenu(
      menuItem(selectInput("b", "b:", c(1,2),selected = 1), tabName ="Tab1"),
      menuItem(selectInput("t", "t:", c(1,2),selected = 1), tabName ="Tab1"),
      menuItem(downloadButton('downloadData', label= 'Download', class= "mybutton"), tabName ="Tab1"),
      menuItem(uiOutput("Text"), tabName ="Tab1"),
      menuItem(selectInput("Plot3Input", "Input:", c(1,2,3,4,5,6),selected = 1), tabName ="Tab2")
    ),
       tags$head(tags$style(".mybutton{background-color:red;} .skin-black .sidebar .mybutton{color: green;}") )

    ),
#   dashboardBody(
#     # Boxes need to be put in a row (or column)
#     tabItems(
#                   tabItem(tabName = "Tab1", 
#                         fluidRow(
#                           column(width=6, 
#                                  box(plotOutput("plot1", height = 250))
#                           ),
#                           column(width=6, 
#                                  box(plotOutput("plot2", height = 250))
#                           )
#                         )
#                     ),
#                     tabItem(tabName = "Tab2",
#                       fluidRow(
#                         column(width=6, 
#                                box(plotOutput("plot3", height = 250))
#                         )
#                       )
#                     )
#             )
#   )#end dashboard

  dashboardBody(
    fluidRow(
      tabBox(
        title = "First tabBox",
        id = "tabset1", height = "400px",
        tabPanel("Tab1", box(plotOutput("plot1", height = 250)),
                 box(plotOutput("plot2", height = 250))),
        tabPanel("Tab2", plotOutput("plot3", height = 250)),width=11
      )
    )
  )

)

运行应用程序的代码

library(shiny)
runApp("C://Users/me/pathtofolder")

以下是您可以看到没有标签的输出:

enter image description here

1 个答案:

答案 0 :(得分:0)

使用以下命令更改ui.R的相应代码块:

dashboardBody(
  fluidRow(
    tabBox(
      title = "First tabBox",
      id = "tabset1", height = "400px",
      tabPanel("Tab1", box(plotOutput("plot1", height = 250)),
           box(plotOutput("plot2", height = 250))),
      tabPanel("Tab2", plotOutput("plot3", height = 250)),width=11
    )
  )
)

enter image description here