MWController-class {manipulateWidget}R Documentation

Controller object of a manipulateWidget application

Description

MWController is a reference class that is used to manage interaction with data and update of the view created by manipulateWidget. Only users who desire to create automatic tests for applications created with manipulateWidget should care about this object.

Fields

ncharts

Number of charts in the application

nrow

Number of rows.

ncol

Number of columns.

autoUpdate

Boolean indicating if charts should be automatically updated when a value changes. list with value and initBtn (not autoUpdate, if want first charts on init)

Methods

getParams(name, chartId = 1)

Get parameters of an input for a given chart

getValue(name, chartId = 1)

Get the value of a variable for a given chart.

getValues(chartId = 1)

Get all values for a given chart.

isVisible(name, chartId = 1)

Indicates if a given input is visible

returnCharts()

Return all charts.

setValue(name, value, chartId = 1, updateHTML = FALSE, reactive = FALSE)

Update the value of a variable for a given chart.

setValueAll(name, value, updateHTML = TRUE)

Update the value of an input for all charts

updateCharts()

Update all charts.

Testing a manipulateWidget application

When manipulateWidget is used in a test script, it returns a MWController object instead of starting a shiny gadget. This object has methods to modify inputs values and check the state of the application. This can be useful to automatically checks if your application behaves like desired. Here is some sample code that uses package testthat:

library("testthat")

controller <- manipulateWidget(
  x + y,
  x = mwSlider(0, 10, 5),
  y = mwSlider(0, x, 0),
  .compare = "y"
)

test_that("Two charts are created", {
  expect_equal(controller$ncharts, 2)
})

test_that("Parameter 'max' of 'y' is updated when 'x' changes", {
  expect_equal(controller$getParams("y", 1)$max, 5)
  expect_equal(controller$getParams("y", 2)$max, 5)
  controller$setValue("x", 3)
  expect_equal(controller$getParams("y", 1)$max, 3)
  expect_equal(controller$getParams("y", 2)$max, 3)
})


[Package manipulateWidget version 0.11.1 Index]