Strange behavior in noUiSliderInput() when formatting decimal to integer, e.g., 5.00 to 5.

huangapple go评论63阅读模式
英文:

Strange behaviour in noUiSliderInput() when formating decimal to integer e.g. 5.00 to 5

问题

noUiSliderInput()函数中,默认情况下数字以小数形式显示,如:5.00。要更改为整数形式,例如:5,我们可以使用参数format,如下所示:format = list(wNumbFormat(decimals = 0, thousand = ",", prefix = "$"))。这只在部分情况下有效,如下所示:

library(shiny)
library(shinyWidgets)

ui <- fluidPage(

  div(style = &#39;position: absolute;left: 150px; top:270px; width:950px;margin:auto&#39;,
  noUiSliderInput(
    inputId = &quot;noui2&quot;, label = &quot;Slider vertical:&quot;,
    min = 0, max = 45, step = 1,
    value = c(15, 20), margin = 10,
    orientation = &quot;vertical&quot;,
    width = &quot;100px&quot;, height = &quot;300px&quot;,
    format = list(wNumbFormat(decimals = 0, thousand = &quot;,&quot;, prefix = &quot;$&quot;))
  ),
  verbatimTextOutput(outputId = &quot;res2&quot;)
  )
)

server <- function(input, output, session) {
  output$res2 <- renderPrint(input$noui2)
}

shinyApp(ui, server)

这种行为的原因是什么?

英文:

In noUiSliderInput() the numbers are shown as decimal by default like: 5.00
To change to integer like: 5

we can use the argument format: format = list(wNumbFormat(decimals = 0, thousand = &quot;,&quot;, prefix = &quot;$&quot;))

This only works partially like here:

library( shiny )
library( shinyWidgets )

ui &lt;- fluidPage(

  div(style = &#39;position: absolute;left: 150px; top:270px; width:950px;margin:auto&#39;,
  noUiSliderInput(
    inputId = &quot;noui2&quot;, label = &quot;Slider vertical:&quot;,
    min = 0, max = 45, step = 1,
    value = c(15, 20), margin = 10,
    orientation = &quot;vertical&quot;,
    width = &quot;100px&quot;, height = &quot;300px&quot;,
    format = list(wNumbFormat(decimals = 0, thousand = &quot;,&quot;, prefix = &quot;$&quot;))
  ),
  verbatimTextOutput(outputId = &quot;res2&quot;)
  )
)
server &lt;- function(input, output, session) {
  output$res2 &lt;- renderPrint(input$noui2)
}
shinyApp(ui, server)

Strange behavior in noUiSliderInput() when formatting decimal to integer, e.g., 5.00 to 5.

What is the reason for this behavior?

答案1

得分: 2

我不确定为什么您将 wNumbFormat 包装在一个 list 中,但请注意,虽然您将前缀设置为 "$",但它不会显示在您的图形/视频中,这表明您的选项没有被使用。

移除 list 部分,它将正常工作:

ui <- fluidPage(

  div(style = 'position: absolute;left: 150px; top:270px; width:950px;margin:auto',
  noUiSliderInput(
    inputId = "noui2", label = "Slider vertical:",
    min = 0, max = 45, step = 1,
    value = c(15, 20), margin = 10,
    orientation = "vertical",
    width = "100px", height = "300px",
    format = wNumbFormat(decimals = 0, thousand = ",", prefix = "$")
  ),
  verbatimTextOutput(outputId = "res2")
  )
)

Strange behavior in noUiSliderInput() when formatting decimal to integer, e.g., 5.00 to 5.

英文:

I'm not sure why you are wrapping wNumbFormat in a list, but notice that while you set the prefix to &quot;$&quot;, it does not show up in your graphic/video, suggesting that your options are not being used.

Remove the list and it works:

ui &lt;- fluidPage(

  div(style = &#39;position: absolute;left: 150px; top:270px; width:950px;margin:auto&#39;,
  noUiSliderInput(
    inputId = &quot;noui2&quot;, label = &quot;Slider vertical:&quot;,
    min = 0, max = 45, step = 1,
    value = c(15, 20), margin = 10,
    orientation = &quot;vertical&quot;,
    width = &quot;100px&quot;, height = &quot;300px&quot;,
    format = wNumbFormat(decimals = 0, thousand = &quot;,&quot;, prefix = &quot;$&quot;)
  ),
  verbatimTextOutput(outputId = &quot;res2&quot;)
  )
)

Strange behavior in noUiSliderInput() when formatting decimal to integer, e.g., 5.00 to 5.

huangapple
  • 本文由 发表于 2023年2月18日 02:40:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/75488154.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定