英文:
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 = '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 = list(wNumbFormat(decimals = 0, thousand = ",", prefix = "$"))
),
verbatimTextOutput(outputId = "res2")
)
)
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 = ",", prefix = "$"))
This only works partially like here:
library( shiny )
library( shinyWidgets )
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 = list(wNumbFormat(decimals = 0, thousand = ",", prefix = "$"))
),
verbatimTextOutput(outputId = "res2")
)
)
server <- function(input, output, session) {
output$res2 <- renderPrint(input$noui2)
}
shinyApp(ui, server)
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")
)
)
英文:
I'm not sure why you are wrapping wNumbFormat
in a list
, but notice that while you set the prefix to "$"
, it does not show up in your graphic/video, suggesting that your options are not being used.
Remove the list
and it works:
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")
)
)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论