【问题标题】:Mega Menu in shiny R闪亮 R 中的超级菜单
【发布时间】:2022-01-11 21:27:30
【问题描述】:

mega menu shiny R 的问题。

我正在尝试制作一个带有大型菜单的导航栏,但是在运行该应用程序时它似乎无法正常工作,但是,将同源代码放入 html 中确实有效。

下面显示的图像是菜单的外观,图像是 html 代码返回的内容。 我还附上了 HTML 中的代码。

我不知道我做错了什么,我会很感激任何指导。

我的代码如下:

library(shiny)

ui <- fluidPage(
  
  tags$head(
    
    tags$link(
      rel="stylesheet",
      href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"
    ),

    tags$style(
      
      '
* {
  box-sizing: border-box;
}



body {
  margin: 0;
}

.navbar {
  overflow: hidden;
  font-family: Arial, Helvetica, sans-serif;
}

.navbar a {
  float: left;
  font-size: 16px;
  color: white;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}

.dropdown {
  float: right;
  overflow: hidden;
}

.dropdown .dropbtn {
  font-size: 16px;  
  border: none;
  outline: none;
  color: #13347b;
  padding: 24px 16px;
  background-color: inherit;
  font: inherit;
  margin: 0;
}

.subtitle {
  color: white
}

.navbar a:hover, .dropdown:hover .dropbtn {
  background-color: #13347b;
  color: white;
}

.dropdown-content {
  display: none;
  position: absolute;
  background-color: #f9f9f9;
  width: 100%;
  left: 0;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  z-index: 1;
}

.dropdown-content .header {
  background: #13347b;
  padding: 16px;
  color: white;
}

.dropdown:hover .dropdown-content {
  display: block;
}

/* Create three equal columns that floats next to each other */
.column {
  float: left;
  width: 33.33%;
  padding: 10px;
  background-color: #13347b;
  height: 250px;
}

.column a {
  float: none;
  color: black;
  padding: 16px;
  text-decoration: none;
  display: block;
  text-align: left;
}

.column a:hover {
  background-color: #ddd;
}

/* Clear floats after the columns */
.row:after {
  content: "";
  display: table;
  clear: both;
}

/* Responsive layout - makes the three columns stack on top of each other instead of next to each other */
@media screen and (max-width: 600px) {
  .column {
    width: 100%;
    height: auto;
  }
}
'
      
    ),

    
    
    
    
  ),# FIN DEL HEAD ----
  
  
  # INCIO DEL BODY
  tags$body(
    tags$div(
      class = "navbar",
      tags$img(
        src = "https://assets.turbologo.com/blog/en/2020/07/19084433/what-size-should-logo-be.png",
        width = 250)
      ,
    tags$div(
      class = "dropdown",
      tags$button(
        class="dropbtn",
        "Dropdown 1",
        tags$i(class = "fa fa-caret-down")
        ),
      tags$div(
        class="dropdown-content",
        tags$div(class="header",tags$h2("Mega Menu")),
        tags$div(class = "row", 
                 tags$div(class="column",
                          tags$h3(class = "subtitle","Categoria 1"),
                          tags$a(href="#","Link1")),
                 tags$div(class="column",
                          tags$h3(class = "subtitle","Categoria 2"),
                          tags$a(href="#","Link2")),
                 tags$div(class="column",
                          tags$h3(class = "subtitle","Categoria 3"),
                          tags$a(href="#","Link3"))
                 )
      )
    )
    )
    
  )


)

server <- function(input, output) {
  
  
}

# Run the application 
shinyApp(ui = ui, server = server)


shinyApp(ui, server)


HTML:

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
* {
  box-sizing: border-box;
}



body {
  margin: 0;
}

.navbar {
  overflow: hidden;
  font-family: Arial, Helvetica, sans-serif;
}

.navbar a {
  float: left;
  font-size: 16px;
  color: white;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}

.dropdown {
  float: right;
  overflow: hidden;
}

.dropdown .dropbtn {
  font-size: 16px;  
  border: none;
  outline: none;
  color: #13347b;
  padding: 24px 16px;
  background-color: inherit;
  font: inherit;
  margin: 0;
}



.navbar a:hover, .dropdown:hover .dropbtn {
  background-color: #13347b;
  color: white;
}

.dropdown-content {
  display: none;
  position: absolute;
  background-color: #f9f9f9;
  width: 100%;
  left: 0;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  z-index: 1;
}

.dropdown-content .header {
  background: #13347b;
  padding: 16px;
  color: white;
}

.dropdown:hover .dropdown-content {
  display: block;
}

/* Create three equal columns that floats next to each other */
.column {
  float: left;
  width: 33.33%;
  padding: 10px;
  background-color: #13347b;
  height: 250px;
}

.column a {
  float: none;
  color: black;
  padding: 16px;
  text-decoration: none;
  display: block;
  text-align: left;
}

.column a:hover {
  background-color: #ddd;
}

/* Clear floats after the columns */
.row:after {
  content: "";
  display: table;
  clear: both;
}

/* Responsive layout - makes the three columns stack on top of each other instead of next to each other */
@media screen and (max-width: 600px) {
  .column {
    width: 100%;
    height: auto;
  }
}
</style>

<style>
* {box-sizing: border-box;}
body {font-family: Verdana, sans-serif;}
.mySlides {display: none;}
img {vertical-align: middle;}

/* Slideshow container */
.slideshow-container {
  max-width: 1000px;
  position: relative;
  margin: auto;
}

/* Caption text */
.text {
  color: #f2f2f2;
  font-size: 15px;
  padding: 8px 12px;
  position: absolute;
  bottom: 8px;
  width: 100%;
  text-align: center;
}

/* Number text (1/3 etc) */
.numbertext {
  color: #f2f2f2;
  font-size: 12px;
  padding: 8px 12px;
  position: absolute;
  top: 0;
}

/* The dots/bullets/indicators */
.dot {
  height: 15px;
  width: 15px;
  margin: 0 2px;
  background-color: #bbb;
  border-radius: 50%;
  display: inline-block;
  transition: background-color 0.6s ease;
}

.active {
  background-color: #717171;
}

/* Fading animation */
.fade {
  -webkit-animation-name: fade;
  -webkit-animation-duration: 1.5s;
  animation-name: fade;
  animation-duration: 1.5s;
}

@-webkit-keyframes fade {
  from {opacity: .4} 
  to {opacity: 1}
}

@keyframes fade {
  from {opacity: .4} 
  to {opacity: 1}
}

/* On smaller screens, decrease text size */
@media only screen and (max-width: 300px) {
  .text {font-size: 11px}
}
</style>

<style> 

.subtitle {
  color: white;
}


</style>


</head>
<body>

<div class="navbar">
  <img src = "https://assets.turbologo.com/blog/en/2020/07/19084433/what-size-should-logo-be.png"
  width = 250
  />
  <div class="dropdown">
    <button class="dropbtn"> Dropdown 1 
      <i class="fa fa-caret-down"></i>
    </button>
    <div class="dropdown-content">
      <div class="header">
        <h2></h2>
      </div>
<!-- EN ESTA PARTE SE AGREGA EL CONTENIDO DE LAS CATEGORIAS EN L HREF DEL LINK, SE PONE LA DIRECCIÓN, LINK ETC -->
      <div class="row">
        <div class="column">
          <h3 class = "subtitle">Category 1</h3>
          <a href="#">Link 1</a>
          <a href="#">Link 2</a>
          <a href="#">Link 3</a>
        </div>
        <div class="column">
          <h3 class = "subtitle" >Category 2</h3>
          <a href="#">Link 1</a>
          <a href="#">Link 2</a>
          <a href="#">Link 3</a>
        </div>
        <div class="column">
          <h3 class = "subtitle" >Category 3</h3>
          <a href="#">Link 1</a>
          <a href="#">Link 2</a>
          <a href="#">Link 3</a>
        </div>
      </div>
    </div>
  </div>
</div>

</body>
</html>

【问题讨论】:

    标签: html css r shiny


    【解决方案1】:

    shiny 在后台使用 Bootstrap。显然,这会与您的应用程序的预期行为产生冲突。您可以通过将其放在 fluidPage 中来删除此 Bootstrap 依赖项:

    shiny::suppressDependencies("bootstrap")
    

    但是,请注意,这将删除所有不在您的自定义 CSS 中的元素的 Bootstrap 样式。

    【讨论】:

      猜你喜欢
      • 2014-04-21
      • 2019-07-05
      • 2021-09-29
      • 2018-11-18
      • 2019-02-23
      • 2018-10-22
      • 2021-03-21
      • 2021-05-01
      • 2019-11-26
      相关资源
      最近更新 更多