我创建了一个闪亮的应用程序,其中有桌子和图像,而我想要这样的应用程序
https://sar03.shinyapps.io/TestingDash/
在此应用程序中,用户可以先选择诸如生物信息学之类的选项,然后在该用户内部可以选择所需的内容。但是,在我的应用程序中,仅在首页表格中显示。我想以这样的方式更改我的应用程序:我拥有元数据,表格和图像面板,除非用户通过它们进行选择,否则它们的内容是隐藏的
这是我的应用
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)
谢谢您的帮助