附注我已经更新了该帖子,以使其更加清晰!
如何为 html 中的框指定不同的颜色来标记内部和外部应用程序?
我正在尝试将盒子标记为不同的颜色,作为内部外部应用程序的标记。然后这个 html 被传递到一个 rshiny 应用程序中。
内部应用程序是由 内部有 astrazeneca 字样的网页链接定义的,外部链接是那些 没有 astrazeneca 字样的网页链接。
这是我拥有的 html 文件示例(我有大约 50 个 html 文件,但只会提供一个)作为示例:
Gene Expression Analysis
Pathway Analysis
正如您在上面的 html 中看到的,我几乎没有以“astrazeneca”作为单词的链接,例如"https://rstudio-connect.scp.astrazeneca.net/RStudio_FLAT/" 和另一个不带 的,例如“www/bioturing.svg”
这是 rshiny 代码,出于上下文目的:
library(shiny)
ui <- shiny::fluidPage(
theme = shinythemes::shinytheme("united"),
tags$head(tags$style(".navbar {margin-bottom: 0px;}")),
tags$head(
tags$style(".container-fluid {padding-right: 0px; padding-left: 0px;}")
),
navbarPage(
title = div(
img(src = "www/bftb_logo_v8_bare.png", height = "30px"),
"AZ Oncology Bioinformatics Toolbox"
),
windowTitle = "BFTB Landing Page",
tabPanel("Toolbox", icon = icon("wrench"), disable = TRUE,
shinydashboard::dashboardPage(
header = shinydashboard::dashboardHeader(title = " ", titleWidth = 300, disable = TRUE),
shinydashboard::dashboardSidebar(
width = 300 ,
textInput("search_term", "Search for apps:"),
actionButton("search_button", "Search"),
shinydashboard::sidebarMenu(
shinydashboard::menuItem(
"Tools",
tabName = "tools_app",
icon = icon("wrench")
),
shinydashboard::menuSubItem(
"Gene Expression/Signature/Pathways",
tabName = "gene_app",
icon = icon("chart-line")
)
)
),
shinydashboard::dashboardBody(
shinydashboard::tabItems(
shinydashboard::tabItem("tools_app", mod_tools_path_ui("tools_path_ui_1")),
shinydashboard::tabItem("gene_app", mod_gene_expressions_sign_path_ui("gene_expression_sign_path_ui"))
)
)
)
)
)
)
server <- function(input, output){
}
shinyApp(ui = ui, server = server)
以及 2 个模块:工具一
mod_tools_path_ui <- function(id){
ns <- NS(id)
tagList(
)
}
和基因一:
mod_gene_expressions_sign_path_ui <- function(id){
ns <- NS(id)
tagList(
shinydashboard::tabItem(
tabName = "gene_app",
fluidRow(
shiny::headerPanel(h3()),
br(),
htmltools::htmlTemplate("www/gene.html")
)
)
)
} Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
据我了解这个问题(不确定),您要求 CSS 为某些链接设置不同的颜色。
您可以为
a标记使用两个类:<div class="box"> <a class="internal" href="https://rstudio-connect.scp.astrazeneca.net/RStudio_FLAT/" target=”_blank”> <img src="www/FluidigmAnalysisToolkit.v2.png" alt="Box 1"> <p>Fludigm_Browser</p> <p>Perform Fluidigm data analysis</p> </a> </div> <div class="box"> <a class="external" href="https://gtexportal.org/home" target=”_blank”> <img src="www/gtex.png" alt="Box 2"> <p>GTEx Portal</p> <p>Gene expression in normal tissue</p> </a> </div>然后使用这样的CSS:
a.internal:link { color: green; background-color: transparent; text-decoration: none; } a.internal:visited { color: pink; background-color: transparent; text-decoration: none; } a.internal:hover { color: red; background-color: transparent; text-decoration: underline; } a.internal:active { color: yellow; background-color: transparent; text-decoration: underline; } a.external:link { color: crimson; background-color: transparent; text-decoration: none; } a.external:visited { color: cyan; background-color: transparent; text-decoration: none; } a.external:hover { color: midnightblue; background-color: transparent; text-decoration: underline; } a.external:active { color: lime; background-color: transparent; text-decoration: underline; }您应该小心使用
container和box等类名称,因为它们可能已经在 Shiny(dashboard) 中使用。<!DOCTYPE html> <html> <head> <style> .container { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; } .box { width: 200px; height: 200px; margin: 10px; padding: 10px; border: 2px solid black; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; } .box img { max-width: 50%; height: auto; margin-bottom: 10px; } .heading { font-size: 24px; font-weight: bold; text-align: center; margin-top: 50px; } a.internal:link { color: green; background-color: transparent; text-decoration: none; } a.internal:visited { color: pink; background-color: transparent; text-decoration: none; } a.internal:hover { color: red; background-color: transparent; text-decoration: underline; } a.internal:active { color: yellow; background-color: transparent; text-decoration: underline; } a.external:link { color: crimson; background-color: transparent; text-decoration: none; } a.external:visited { color: cyan; background-color: transparent; text-decoration: none; } a.external:hover { color: midnightblue; background-color: transparent; text-decoration: underline; } a.external:active { color: lime; background-color: transparent; text-decoration: underline; } </style> </head> <body> <h2 class="heading">Gene Expression Analysis</h2> <div class="container"> <div class="box"> <a class="internal" href="https://rstudio-connect.scp.astrazeneca.net/RStudio_FLAT/" target=”_blank”> <img src="www/FluidigmAnalysisToolkit.v2.png" alt="Box 1"> <p>Fludigm_Browser</p> <p>Perform Fluidigm data analysis</p> </a> </div> <div class="box"> <a class="external" href="https://gtexportal.org/home" target=”_blank”> <img src="www/gtex.png" alt="Box 2"> <p>GTEx Portal</p> <p>Gene expression in normal tissue</p> </a> </div> </div> </body> </html>