2017-03-08 192 views
2

我有一個R閃亮的滑塊輸入問題。 「圓形特徵」不起作用,您可以在in this picture中看到。我做錯什麼了嗎 ?r閃亮的滑塊輸入輪

sliderInput("Er", "Choose expected return (in percent)", 
       min = min, max = max, value = min , round = -1, 
       sep = "" , post = "%", ticks = FALSE 
     ) 
+1

如果您在將最小值和最大值傳遞給sliderInput()之前嘗試舍入,會發生什麼? –

+0

他們在小數點後一位,它仍然沒有工作。 – Ethan

回答

4

您必須指定一個stepround ING工作:

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)) 
}) 

enter image description here

否則,由@Ryan莫頓評論,如果您使用整數的minmaxround ing即使step = NULL

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)) 
}) 

enter image description here

+0

是否有任何方式最小和最大不是整數(例如,他們四捨五入到小數點後兩位)和舍入工程? – Ethan

+0

@samo請參閱我的編輯 – HubertL

+0

@HubertL我有類似的問題,所以我發現你的答案非常有幫助。我有一個後續問題,使用第一個示例中的代碼,當您滾動到20.40%時,滑塊將顯示20.4%或21%,當在21.00%時。你知道是否有一種方法來顯示尾隨0的整數或0.1?謝謝。 – MJH