【问题标题】:How to apply CSS styling to modularized shiny code?如何将 CSS 样式应用于模块化闪亮代码?
【发布时间】:2019-01-07 13:50:10
【问题描述】:

我正在尝试在我正在制作的闪亮应用中设计我的 UI。我之前构建了一个相当全面的地图,现在我必须对其进行模块化以提高可读性。不幸的是,我似乎无法理解如何在使用模块时应用 CSS 样式。

我尝试应用样式的部分位于底部的 UI 功能中:

div(class="outer",

        tags$head(includeCSS("styles.css")),

          baseMapUI("bottommap")
        )

我不确定是否将 CSS 文件保存在错误的位置。我确实在开始时将工作目录设置为我的/Data 文件夹,所以我也将它保存在那里。由于没有返回错误(即找不到文件),我相信问题出在其他地方。

我的最终结果将是风格化的absolutePanel,但实际上根本没有应用 CSS 样式。作为参考,这是我的 CSS 文件:

input[type="number"] {
  max-width: 80%;
}

div.outer {
  position: fixed;
  top: 41px;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  padding: 0;
}

/* Customize fonts */
body, label, input, button, select { 
  font-family: 'Helvetica Neue', Helvetica;
  font-weight: 200;
}
h1, h2, h3, h4 { font-weight: 400; }

#controls {
  /* Appearance */
  background-color: white;
  padding: 0 20px 20px 20px;
  cursor: move;
  /* Fade out while not hovering */
  opacity: 0.65;
  zoom: 0.9;
  transition: opacity 500ms 1s;
}
#controls:hover {
  /* Fade in while hovering */
  opacity: 0.95;
  transition-delay: 0;
}

/* Position and style citation */
#cite {
  position: absolute;
  bottom: 10px;
  left: 10px;
  font-size: 12px;
}

/* If not using map tiles, show a white background */
.leaflet-container {
  background-color: white !important;
}

【问题讨论】:

  • 应该是#bottommap-controls,而不是#controls
  • 是的,就是这样!如果您将此作为答案提交,我可以选择它作为解决方案。

标签: r shiny r-leaflet


【解决方案1】:

id = ns("controls") 生成 id bottommap-controls。所以选择器必须是#bottommap-controls 而不是#controls

【讨论】:

  • 有没有办法将 ID 从 R 动态传递给闪亮以控制样式或 JS 事件,而不是在您的答案中建议手动硬编码?
猜你喜欢
  • 2020-08-08
  • 1970-01-01
  • 2016-06-21
  • 2022-10-05
  • 2017-12-09
  • 2016-07-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多