Skip to contents

This is the shared framework used by tuneParams() and, in the mizerEcopath package, by tuneEcopath(). Advanced users can also call it directly to build custom tuning gadgets.

Usage

tuningGadget(
  params,
  controls,
  tabs,
  match_choices,
  match_selected,
  action_label,
  action_tooltip,
  action_key,
  action_handler,
  prepare_params_hook = NULL,
  finalise_params_hook = NULL,
  update_species_hook = NULL,
  tab_extra_args = list(),
  preserve = c("erepro", "reproduction_level", "R_max"),
  return_app = FALSE,
  ...
)

Arguments

params

MizerParams object to tune. If missing, the gadget tries to recover information from log files left over from aborted previous runs.

controls

A character vector of names of input parameter control sections that should be displayed in the sidebar.

tabs

A character vector of names of the tabs that should be displayed in the main section.

match_choices

A character vector of the available match options that appear as checkboxes.

match_selected

A character vector indicating which match options are selected by default.

action_label

The HTML label for the main action button (e.g., HTML("<u>s</u>teady")).

action_tooltip

Tooltip text for the main action button.

action_key

JavaScript key code for the keyboard shortcut that triggers the action button (e.g., 83 for 's', 77 for 'm').

action_handler

A function that is called when the action button is pressed. It receives the arguments (p, input, session, params, params_old, logs, flags, trigger_update, ...).

prepare_params_hook

An optional function (p) -> p called after the shared parameter preparation to apply package-specific defaults.

finalise_params_hook

An optional function (p) -> p called after the shared parameter finalisation to apply package-specific cleanup.

update_species_hook

An optional function (sp, p) -> p called inside tuneParams_update_species() after steadySingleSpecies() to apply package-specific post-processing (e.g., matchBiomasses()).

tab_extra_args

A named list of extra arguments to pass to tab server functions (e.g., list(catch = catch, diet = diet)).

preserve

Specifies whether the reproduction_level should be preserved or the maximum reproduction rate R_max or the reproductive efficiency erepro (Default). See setBevertonHolt() for an explanation of the reproduction_level.

return_app

Boolean. For testing purposes only. When set to TRUE will return a shinyApp object instead of running the gadget.

...

Other params needed by individual tabs.

Value

The tuned MizerParams object

Details

The function opens a shiny gadget with a sidebar of parameter controls and a main panel of diagnostic tabs.

How parameter changes take effect

When you change a model parameter, only the steady-state size spectrum of the currently selected species is recalculated. The growth and mortality rates that drive this recalculation are first evaluated from the previous state of the model — with the abundances of every species and of the resource, including the selected species itself, held fixed — and are then kept constant while the new spectrum is solved for. So the prey and predators of the selected species do not react to your change, and neither does the species' own recomputed abundance feed back into its rates: there is no multi-species feedback within a single update. In an interacting model, to let the whole community respond and settle into a new, mutually consistent steady state you must press the action button (the "steady" button in tuneParams()). See vignette("extending_the_tuning_gadget") for a fuller explanation.

Undo functionality

The gadget keeps a log of all steady states you create while working with the gadget. You can go back to the last steady state by hitting the "Undo" button. You can go back an arbitrary number of states and also go forward again. There is also a button to go right back to the initial steady state.

When you leave the gadget by hitting the "Return" button, this log is cleared. If you stop the gadget from RStudio by hitting the "Stop" button, then the log is left behind. You can then restart the gadget by calling tuneParams() without a params argument and it will re-instate the states from the log.

Customisation

You can customise which functionality is included in the app via the controls and tabs arguments. You can remove some of the controls and tabs by providing shorter lists to those arguments. You can also add your own controls and tabs.

For an entry "foo" in the controls list there needs to be a function "fooControlUI" that defines the input elements and a function "fooControl" that processes those inputs to change the params object.

For any entry "Foo" or "foo" in the tabs list there needs to be a function "fooTabUI" that defines the tab layout and a function "fooTab" that calculates the outputs to be displayed on the tab.