【问题标题】:want to create custom numericRangeInput with similar arguments想要创建具有相似参数的自定义 numericRangeInput
【发布时间】:2021-12-07 00:36:39
【问题描述】:

出于美学原因,我正在制作一个与 [shinyWidgets] 中的功能相同的自定义 numericRangeInput。1 但是,我在模仿这一论点时遇到了麻烦。

我想要一个 inputId 用于整个组件,我可以用与 shinyWidget 的输入相同的方式调用这些值。

这是我目前所拥有的:

library(tidyverse)

numeric_input_ui <- function(title = "title", text = "to", id = c("id1","id2"), placeholder = c(0,0), value = c(0,0)){
  HTML(
    str_glue(
      '<label>{title}
      <div class="input-group input-group-sm m-4" style="margin:0px!important;margin-top:5px!important;margin-bottom:10px!important;">
  <input class="form-control" type="number" id="{id[1]}" placeholder="{placeholder[1]}" value="{value[1]}">
  <div class="input-group-prepend input-group-append">
    <div class="input-group-text">{text}</div>
  </div>
  <input class="form-control" type="number" id="{id[2]}" placeholder="{placeholder[2]}" value="{value[2]}"></input>
</div>
      </label>'
    )
  )
}

如您所见,我现在用两个 ID 设置了它...这使得管理服务器端时很头疼,因为我试图在闪亮的应用程序上实现它。欢迎在我的问题之外对函数本身提出任何建议!

【问题讨论】:

    标签: html r bootstrap-4 shiny shinywidgets


    【解决方案1】:

    我不确定是否理解。为什么不使用你拆分的唯一 id:

    numeric_input_ui <- function(
      title = "title", text = "to", id, placeholder = c(0,0), value = c(0,0)
    ){
      id1 <- paste0(id, "1")
      id2 <- paste0(id, "2")
      HTML(
        str_glue(
          '
    <label>
       {title}
       <div class="input-group input-group-sm m-4" style="margin:0px!important;margin-top:5px!important;margin-bottom:10px!important;">
          <input class="form-control" type="number" id="{id1}" placeholder="{placeholder[1]}" value="{value[1]}">
          <div class="input-group-prepend input-group-append">
             <div class="input-group-text">{text}</div>
          </div>
          <input class="form-control" type="number" id="{id2}" placeholder="{placeholder[2]}" value="{value[2]}">
       </div>
    </label>
    '
        )
      )
    }
    

    然后在服务器中使用返回两个值的反应导体:

    numInput <- reactive({
      c(input[[paste0(id, "1")]], input[[paste0(id, "2")]])
    })
    

    这种方式有什么不方便的地方?没有更多的上下文,很难找出你的问题。

    【讨论】:

    • 我想知道我是否在 html 组件本身中遗漏了一些东西,因为 shinyWidgets 版本(据我了解)不需要单独的反应函数来分隔值。我的问题是可扩展性,我正在尝试在表格上构建一个自定义过滤器,并且其中可能会有很多数字输入。我不确定除了您所说的之外是否还有其他解决方案,因为我遇到了同样的问题,否则没关系!但是,是的,这主要是我要问的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-07
    • 2012-07-04
    • 1970-01-01
    • 2019-11-05
    • 1970-01-01
    • 1970-01-01
    • 2018-11-09
    相关资源
    最近更新 更多