我整理了一个闪亮的应用程序。现在,我需要在其中添加另一个面板,但是只需在代码中添加额外的mainplanel,我的其他两个面板就会被停用
这是我的应用
navbarPageWithText <- function(..., text) {
navbar <- navbarPage(...)
textEl <- tags$p(class = "navbar-text", text)
navbar[[3]][[1]]$children[[1]] <- htmltools::tagAppendChild(
navbar[[3]][[1]]$children[[1]], textEl)
navbar
}
# Call this function with an input (such as `textInput("text", NULL, "Search")`) if you
# want to add an input to the navbar
navbarPageWithInputs <- function(..., inputs) {
navbar <- navbarPage(...)
form <- tags$form(class = "navbar-form", inputs)
navbar[[3]][[1]]$children[[1]] <- htmltools::tagAppendChild(
navbar[[3]][[1]]$children[[1]], form)
navbar
}
library(shiny)
library(DT)
Patient_005=as.data.frame(read.table(text = " Driver SNV_Tumour_005 SNV_Organoid_005 INDEL_Tumour_005 INDEL_Organoid_005 Deletion_Organoid_005
ABCB1 * * * - - -
ACVR1B * * - - - -
ACVR2A * - - - - -
"))
Patient_013=as.data.frame(read.table(text = " Driver SNV_Tumour_013 SNV_Organoid_013 INDEL_Tumour_013 INDEL_Organoid_013 Deletion_Tumour_013 Deletion_Organoid_013
ABCB1 * - * - - - -
ACVR1B * - - - - - -
ACVR2A * - - - - - -
"))
Patient_036 = as.data.frame(read.table(text = " Driver SNV_Organoid_036 INDEL_Organoid_036 Deletion_Organoid_036
ABCB1 * - * -
ACVR1B * * * -
ACVR2A * * - -
"))
Patient_021 = as.data.frame(read.table(text = " Driver SNV_Organoid_021 INDEL_Organoid_021
ABCB1 * * -
ACVR1B * * -
ACVR2A * * *
"))
ui <- shinyUI(navbarPage("Patients",
tabPanel("Table",theme = "bootstrap.css",
headerPanel("Genomic variations in OESO driver genes"),
sidebarPanel(br(),
tags$style("#select1 {border: 2px solid #dd4b39;}"), div(
id = "loading-content",
h2("Binary output"), navbarPageWithText(
"* means that gene carries an event",
text = "- means that no event has been observed"
)
),
selectInput(
"table_dataset",
"Choose patient:",
choices = c("Patient_005","Patient_013","Patient_036","Patient_021")
)
),
mainPanel(DT::dataTableOutput("table"))
),
tabPanel("Image",
sidebarPanel( br(),
tags$style("#select2 {background-color:blue;}"),
selectInput(
"image_dataset",
"Choose image:",
choices = c("Mutational_Signatures"="https://i.ibb.co/hZYc9nM/Mutational-Signatures1.png", "Total_and_Minor_Copy_Number" = "https://i.ibb.co/pRYxfwF/Total-and-Minor-Copy-Number.png", "Structural_Variations" = "https://i.ibb.co/JB4z6y6/Strutural-Variations.png", "Statistics" = "https://i.ibb.co/DYm2nm4/Statistics.png" , "Major_and_Minor_Copy_Number" = "https://i.ibb.co/ZV3DTXN/Major-and-Minor-Copy-Number.png", "Mutational_consequences_SNVs" = "https://i.ibb.co/CpyqRdr/Mutational-consequences.png" , "Mutational_consequences_INDEL" = "https://i.ibb.co/Vt4nwqd/Mutational-consequences-indel.png" , "Segment_mean" = "https://i.ibb.co/Cthk4ZD/Segment-mean.png" , "RNA_seq_Driver_Genes" = "https://i.ibb.co/qr9cvdN/RNA-seq.png"
)
)
),
mainPanel(
uiOutput("image")
), div(
id = "loading-content",
h2("Loading..."), navbarPageWithText(
"Images of",
text = "Organoid models"
)
)
),tags$head(
tags$style(type = 'text/css',
HTML('.navbar { background-color: skin-blue;}
.navbar-default .navbar-brand{color: black;}
.tab-panel{ background-color: skin-blue; color: black}
.navbar-default .navbar-nav > .active > a,
.navbar-default .navbar-nav > .active > a:focus,
.navbar-default .navbar-nav > .active > a:hover {
color: #555;
background-color: pink;
}')
)
)
))
server <- function(input, output) {
# Related to displaying tables
table_data <- reactive({
switch(input$table_dataset, "Patient_005" = Patient_005 ,"Patient_013" = Patient_013,"Patient_036" = Patient_036,"Patient_021" = Patient_021)
})
column_data <- reactive({
switch(input$table_dataset,
"Patient_005" = c('Driver','SNV_Tumour_005','SNV_Organoid_005','INDEL_Tumour_005','INDEL_Organoid_005','Deletion_Organoid_005'),
"Patient_013" = c('SNV_Tumour_013','SNV_Organoid_013','INDEL_Tumour_013','INDEL_Organoid_013','Deletion_Tumour_013','Deletion_Organoid_013')
)
})
output$table <- DT::renderDataTable({
datatable(table_data()) %>%
formatStyle(
column_data(),
backgroundColor = styleEqual(c("*", "-"), c('green', 'red'))
)
})
# Related to displaying images
output$image <- renderUI({
tags$img(src = input$image_dataset)
})
}
shinyApp(ui=ui,server=server)
我需要将此表添加为标题为MetaData的另一个面板
> head(MetaData)
Clinical.ID Barcode WTSI.Model.ID Tissue.Origin
1 OCC/SH/253/S/T 2000003422203 WTSI-OESO_005 Oesophageal
2 OCC/SH/254/S/T CGAP-A3F3F WTSI-OESO_013 Oesophageal
3 OCC/SH/255/S/T CGAP-73FED WTSI-OESO_036 Oesophageal
4 OCC/SH/255/S/N CGAP-70672 WTSI-OESO_037 Oesophageal
Sample.type
1 Tumour
2 Tumour
3 Tumour
4 Normal
>
> dput(head(MetaData))
structure(list(Clinical.ID = structure(c(1L, 2L, 4L, 3L), .Label = c("OCC/SH/253/S/T",
"OCC/SH/254/S/T", "OCC/SH/255/S/N", "OCC/SH/255/S/T"), class = "factor"),
Barcode = structure(c(1L, 4L, 3L, 2L), .Label = c("2000003422203",
"CGAP-70672", "CGAP-73FED", "CGAP-A3F3F"), class = "factor"),
WTSI.Model.ID = structure(1:4, .Label = c("WTSI-OESO_005",
"WTSI-OESO_013", "WTSI-OESO_036", "WTSI-OESO_037"), class = "factor"),
Tissue.Origin = structure(c(1L, 1L, 1L, 1L), .Label = "Oesophageal", class = "factor"),
Sample.type = structure(c(2L, 2L, 2L, 1L), .Label = c("Normal",
"Tumour"), class = "factor")), row.names = c(NA, 4L), class = "data.frame")
>
您能帮我将此表格添加为我的应用的第三个面板吗?