r 闪亮滑块输入轮
r shiny slider input round
我对 R 闪亮滑块输入有疑问。正如您在 in this picture 中看到的那样,"Round feature" 不起作用。我是不是做错了什么?
sliderInput("Er", "Choose expected return (in percent)",
min = min, max = max, value = min , round = -1,
sep = "" , post = "%", ticks = FALSE
)
您必须指定 step
才能使 round
工作:
library(shiny)
min_Er <- 20.31
max_Er <- 23.59
shinyApp( ui = fluidPage(sliderInput("Er1", "Rounding doesn't work",
round = -2, step = NULL,
min = min_Er,
max = max_Er,
value = min_Er,
sep = "" , post = "%", ticks = FALSE),
sliderInput("Er2", "Rounding works",
round = -2, step = 0.01,
min = min_Er,
max = max_Er,
value = min_Er,
sep = "" , post = "%", ticks = FALSE)
), server=function(input, output, session){
observe(print(input$Er1))
observe(print(input$Er2))
})
否则,正如@Ryan Morton 评论的那样,如果您对 min
和 max
使用整数,即使 step = NULL
:[=20,round
ing 也能正常工作=]
library(shiny)
min_Er <- 20.31
max_Er <- 23.59
shinyApp(ui = fluidPage(sliderInput("Er1", "Rounding doesn't work",
round = TRUE,
min = min_Er,
max = max_Er,
value = min_Er,
sep = "" , post = "%", ticks = FALSE),
sliderInput("Er2", "Rounding works",
round = TRUE,
min = floor(min_Er),
max = ceiling(max_Er),
value = min_Er,
sep = "" , post = "%", ticks = FALSE)
), server=function(input, output, session){
observe(print(input$Er1))
observe(print(input$Er2))
})
我对 R 闪亮滑块输入有疑问。正如您在 in this picture 中看到的那样,"Round feature" 不起作用。我是不是做错了什么?
sliderInput("Er", "Choose expected return (in percent)",
min = min, max = max, value = min , round = -1,
sep = "" , post = "%", ticks = FALSE
)
您必须指定 step
才能使 round
工作:
library(shiny)
min_Er <- 20.31
max_Er <- 23.59
shinyApp( ui = fluidPage(sliderInput("Er1", "Rounding doesn't work",
round = -2, step = NULL,
min = min_Er,
max = max_Er,
value = min_Er,
sep = "" , post = "%", ticks = FALSE),
sliderInput("Er2", "Rounding works",
round = -2, step = 0.01,
min = min_Er,
max = max_Er,
value = min_Er,
sep = "" , post = "%", ticks = FALSE)
), server=function(input, output, session){
observe(print(input$Er1))
observe(print(input$Er2))
})
否则,正如@Ryan Morton 评论的那样,如果您对 min
和 max
使用整数,即使 step = NULL
:[=20,round
ing 也能正常工作=]
library(shiny)
min_Er <- 20.31
max_Er <- 23.59
shinyApp(ui = fluidPage(sliderInput("Er1", "Rounding doesn't work",
round = TRUE,
min = min_Er,
max = max_Er,
value = min_Er,
sep = "" , post = "%", ticks = FALSE),
sliderInput("Er2", "Rounding works",
round = TRUE,
min = floor(min_Er),
max = ceiling(max_Er),
value = min_Er,
sep = "" , post = "%", ticks = FALSE)
), server=function(input, output, session){
observe(print(input$Er1))
observe(print(input$Er2))
})