rp.slider: Slider for an rpanel

View source: R/slider.r

rp.sliderR Documentation

Slider for an rpanel

Description

Add a slider (or slider group) to the panel, to graphically control a numeric variable.

Usage

rp.slider(panel, variable, from, to, action=I, labels=NULL, names=NULL, title=NULL,
  log=rep(FALSE, length(from)), showvalue=FALSE, showvaluewidth=4, resolution=0,
  initval=from, pos=NULL, 
  horizontal=TRUE, foreground=NULL, background=NULL, font=NULL, 
  parentname=deparse(substitute(panel)), name=paste("slider", .nc(), sep=""), ...) 
rp.slider.change(panel, name, value, i=1, do=TRUE)

Arguments

panel

the panel in which the slider appears.

variable

the name of the variable that the slider controls.

from

the lower limit of the range of values to which the slider can be set.

to

the upper limit of the range of values to which the slider can be set.

action

the function which is called when the slider is moved.

labels

displayed labels

names

the names of the elements of variable, for reference by action functions.

title

the label of the slider.

log

a logical variable which controls whether the scale of the slider is logarithmic.

showvalue

a logical variable which determines whether the present value of "var" is shown. This is forced to FALSE when log is TRUE.

showvaluewidth

the number of significant digits in the shown value

resolution

the resolution of the slider scale. If > 0, all values are rounded to an even multiple of this value. The default is 0.

initval

the initial value of var (optional). The initial value can also be specified in the call to rp.control.

pos

the layout instructions. Please see the rp.pos example and help for full details.

horizontal

a logical variable determining whether the slider is displayed horizontally (or vertically).

foreground

colour of the text

background

colour of the text background

font

font to be used

parentname

this specifies the widget inside which the slider should appear.

name

name assigned to the slider, used for disposing of the widget

...

...

value

new value for the slider

i

which slider to alter

do

whether to call the action event

Details

The function action should take one argument, which should be the panel to which the slider is attached.

See rp.grid for details of the grid layout system.

Warning

The action function should return the panel. Without this assignment any widgets added or alterations made to panel parameters within the action function will be lost.

Note that setting log=TRUE and showvalue=TRUE is not allowed. The slider value shown would be incorrect (it wouldn't be the log value) and so showvalue is over-ridden and set to FALSE. A new widget rp.label is under development which would be used in these circumstances.

Note

New for version 2.0 is support for multiple sliders in a group. See demo(rp.slider).

References

rpanel: Simple interactive controls for R functions using the tcltk package. Journal of Statistical Software, 17, issue 9.

See Also

rp.radiogroup,rp.control

Examples

## Not run: 
density.draw <- function(panel) {
   plot(density(panel$x, bw = panel$h))
   panel
   }
panel <- rp.control(x = rnorm(50))
rp.slider(panel, h, 0.5, 5, log = TRUE, action = density.draw)
   
printer <- function(panel) {
  print(panel$h)
  panel
}
panel <- rp.control(x = rnorm(50), h=c(1,2,3))
rp.slider(panel, h, c(0.5,0.5,0.5), c(5,5,5),
  log = c(TRUE,TRUE,TRUE), action = printer,
  title=c('h','h1','h2'), initval=c(1,2,3))
    
# An example which changes the slider position through another widget
    
draw <- function(panel) {
  hist(panel$x)
  abline(v=panel$v, col="red", lty=2)
  panel
}

redraw <- function(panel) {
  rp.tkrreplot(panel, plot)
  panel
}

redraw1 <- function(panel) {
  rp.tkrreplot(panel, plot)
  rp.slider.change(panel, "slider", panel$v)
  panel
}

x <- rnorm(25)
panel <- rp.control(v = 0, x = x)
rp.tkrplot(panel, plot, draw, pos="right")
rp.slider(panel, v, min(x), max(x), redraw, name = "slider")
rp.doublebutton(panel, v, diff(range(x))/100, action=redraw1)


## End(Not run)

rpanel documentation built on Feb. 16, 2023, 10:37 p.m.

Related to rp.slider in rpanel...