mwSharedValue: Shared Value

Description Usage Arguments Value See Also Examples

View source: R/inputs.R

Description

This function creates a virtual input that can be used to store a dynamic shared variable that is accessible in inputs as well as in output.

Usage

1

Arguments

expr

Expression used to compute the value of the input.

Value

An Input object of type "sharedValue".

See Also

Other controls: mwCheckboxGroup(), mwCheckbox(), mwDateRange(), mwDate(), mwGroup(), mwNumeric(), mwPassword(), mwRadio(), mwSelectize(), mwSelect(), mwSlider(), mwText()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
if (require(plotly)) {
  # Plot the characteristics of a car and compare with the average values for
  # cars with same number of cylinders.
  # The shared variable 'subsetCars' is used to avoid subsetting multiple times
  # the data: this value is updated only when input 'cylinders' changes.
  colMax <- apply(mtcars, 2, max)

  plotCar <- function(cardata, carName) {
    carValues <- unlist(cardata[carName, ])
    carValuesRel <- carValues / colMax

    avgValues <- round(colMeans(cardata), 2)
    avgValuesRel <- avgValues / colMax

    plot_ly() %>%
      add_bars(x = names(cardata), y = carValuesRel, text = carValues,
               hoverinfo = c("x+text"), name = carName) %>%
      add_bars(x = names(cardata), y = avgValuesRel, text = avgValues,
               hoverinfo = c("x+text"), name = "average") %>%
      layout(barmode = 'group')
  }

  c <- manipulateWidget(
    plotCar(subsetCars, car),
    cylinders = mwSelect(c("4", "6", "8")),
    subsetCars = mwSharedValue(subset(mtcars, cylinders == cyl)),
    car = mwSelect(choices = row.names(subsetCars))
  )
}

manipulateWidget documentation built on Oct. 5, 2021, 9:10 a.m.