简体   繁体   English

使用HTML的R闪亮输出的属性

[英]Attributes of R shiny outputs using HTML

The given script creates an action button and a slider in r shiny. 给定的脚本在r shine中创建一个动作按钮和一个滑块。 If I wish to give certain attributes to {{ button }} in html script like position, margin from left, height and width, please help me with this. 如果我希望在html脚本中为{{button}}提供某些属性,例如位置,左边距,高度和宽度,请帮助我。

<!-- template.html -->
<html>
<head>
{{ headContent() }}
</head>
<body>
<div>
{{ button }}
{{ slider }}
</div>
</body>
</html>

## ui.R ##
htmlTemplate("template.html",
button = actionButton("action", "Action"),
slider = sliderInput("x", "X", 1, 100, 50)
)

reproducible example, note that action button can be styled directly by using #action selector however slider input has container therefore positioning of the slider as such should be done at container level and cannot be done by selecting id. 可重现的示例,请注意,可以通过使用#action选择器直接设置操作按钮的样式,但是滑块输入具有容器,因此应在容器级别完成滑块的定位,而不能通过选择id来完成。 As far as i know css selector doesnt have equivalent of jquery :has() 据我所知,css选择器没有jquery的等效项:has()

library(shiny)
shinyApp(
  ui <- fluidPage(
    fluidRow(actionButton("action", "Action"),sliderInput("x", "X", 1, 100, 50)),
    tags$head(
      tags$style('#action { margin:3px;border:2px solid green;padding 20px;}
                 .slider-custom-format { margin:3px;border:1px solid red;}
                 .slider-custom-format .irs-bar,.slider-custom-format .irs-bar-edge{background:red;}'),
      tags$script('$(function(){
                  $(".form-group.shiny-input-container:has(#x)").addClass("slider-custom-format")
                  })')
)
  ),
  server <- function(input, output) {})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM