 # Two ended slider input

Hi,

I am trying to plot a uniform distribution, with the second slider input being the issue. I want to have the maximum and minimum values of the slider change the endpoints of the uniform distribution, but i can't seem to get the two values for the two endpoints of the uniform distribution, out of the slider. Here are the relevant code sections from the server and ui files respectively.

Any help would be greatly appreciated.

#uniform distribution
conditionalPanel(
condition="input.illustration==\"unif\"",
sliderInput("unif.n",withMathJax(helpText("Number of observations : \$$n\$$")),min=-10,max=10,value=1,step=1),
sliderInput("unif.minmax",withMathJax(helpText("Lower and upper bounds : \$$minmax\$$")),min = -20, max = 20,value = c(-15,15))
),

    if (input$illustration=="unif"){ par(mar=c(2.1,2.1,0.1,0.1)) n <- input$unif.n
minmax <- input$unif.minmax x <- seq(0,10,length.out=500) plot(x,dunif(x,minmax),type="l",xlab="",ylab="") }  When you have a two-ended sliderInput in Shiny, the resulting choices appear as a vector, i.e. print(input$unif.minmax) with its default values would result in  -15 15. So to access the minimum value, you would use input$unif.minmax and to access the maximum value, you would use input$unif.minmax. So your if statement above would appear as the following:

    if (input$illustration=="unif"){ par(mar=c(2.1,2.1,0.1,0.1)) n <- input$unif.n
minmax <- input\$unif.minmax
x <- seq(0,10,length.out=500)
plot(x,dunif(x,minmax,minmax),type="l",xlab="",ylab="")
}

1 Like

Perfect!

That worked for me, thanks!

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.