闪亮滑块定制值

时间:2017-08-19 22:04:11

标签: r shiny

我正在尝试为闪亮滑块(1,5,10,15,20,25和30)设置自定义值。我试过step但结果是(0,5,10,15,20,25,30)或(1,6,11,16,21,26,31)。有没有办法为滑块定义自定义值? 谢谢!

plotpath <- "/Volumes/share-ites-1-$/Projects/Scientifica/Simulations_Scientifica"

ui <- fluidPage(
     titlePanel("LandClim Simulations"),
     sidebarLayout(
          sidebarPanel(
               sliderInput(inputId = "temp", 
                           label = "Temperature increase:", 
                           value = 1, min = 1, max = 2,
                           step = 1, animate = TRUE ),
               sliderInput(inputId = "prec", 
                           label = "Precipitation change:", 
                           value = 0, min = -2, max = 2,
                           step = 1, animate = TRUE ),
               sliderInput(inputId = "decade", 
                           label = "Time (decade):", 
                           value = 1, min = 0, max = 30,
                           step = 5, animate = TRUE )
          ),
          mainPanel(imageOutput("image")) 
     )
)

server <- function(input, output) {
     output$image <- renderImage( deleteFile = FALSE, {
               return(list(
                    src = paste(plotpath,"/Temp",input$temp,"Prec",input$prec,"Dec",input$decade,".png",sep = ""),
                    contentType = "image/png"))
     } ) }

shinyApp(ui = ui, server = server)

4 个答案:

答案 0 :(得分:7)

shinyWidgets包现在可以通过允许自定义值的滑块为您解决此问题。第三个滑块的更新代码如下所示:

shinyWidgets::sliderTextInput(inputId = "decade", 
  label = "Time (decade):", 
  choices = c(1,5,10,15,20,25,30))

答案 1 :(得分:0)

虽然Shiny提供了自定义滑块输入的选项,但我认为没有办法在表格中获得输出(1,5,10 ...)。这是因为你的第一和第二点之间的差异是4,此后它是5,这将与步骤参数的工作方式不一致。。步骤只能根据滑块输入之间的常数差异生成数字。

答案 2 :(得分:0)

使用闪亮的sliderTextInput函数可以轻松完成此操作。无需添加所有这些复杂的js函数。只需执行几行代码即可。安装包含sliderTextInput函数的shinywidgets软件包。执行以下操作:

  sliderTextInput("decade","Time (decade):, 
                  choices = c(1,5,10,15,20,25,30), 
                  selected = c(1,5,10,15,20,25,30), 
                  animate = FALSE, grid = FALSE, 
                  hide_min_max = FALSE, from_fixed = FALSE,
                  to_fixed = FALSE, from_min = NULL, from_max = NULL, to_min = NULL,
                  to_max = NULL, force_edges = FALSE, width = NULL, pre = NULL,
                  post = NULL, dragRange = TRUE)

答案 3 :(得分:-1)

根据需要使用滑块,要使输入具有可变中断,您可以使用其他选项之一,例如

selectInput

https://shiny.rstudio.com/reference/shiny/latest/selectInput.html

甚至是checkboxInput

https://shiny.rstudio.com/reference/shiny/latest/checkboxInput.html