Input `actions`
!! Outdated, please see comments below !!
Description
@jcheng5, after describing the current system of showing nav panes and based on my work thus far with {yonder}, I have started implementing a new approach. I agree freezing the layout of an application during a long running process is sub-optimal. The new approach allows inputs to target elements with bootstrap plugins (navs, alerts, modals, etc.) and makes use of the data-target attributes (as you brought up) to trigger these plugin elements.
For now only navInput() has been updated. Below are some potential uses of the new targets argument.
targets is a character string
If targets is a character string the input's values are assumed as id's of plugin elements, i.e. the id of a navPane(). For now, the value "pages" is actually ignored and I am considering using TRUE instead. (The values of an input if not specified default to the choices)
navInput(
id = "test",
choices = c("Home", "About"),
targets = "pages"
)
targets is a character vector
If targets is a character vector each value is considered a corresponding id target for each choice/value of the input. The targets and values are matched by index.
navInput(
id = "test",
choices = c("Home", "About"),
targets = c("chicken", "dinner")
)
targets is a named vector or list
If targets is a named character vector or list the names are used to match input values to a target id. A NULL value may be used to prevent a certain input value from triggering any effect.
navInput(
id = "test",
choices = c("Home", "About"),
values = c("chicken", "dinner")
targets = c(
chicken = "Home",
dinner = "About"
)
)
targets is a list and includes multi-length items
This case allows a single input value to trigger two targets.
navInput(
id = "test",
choices = c("Home"),
targets = list(
Home = c("home_page", "info_panel")
)
)
Demo
If you install the feat/input-targets branch you can try out the following demo.
ui <- webpage(
navInput(
id = "test",
appearance = "tabs",
choices = c("Home", "About"),
targets = c("home_page", "about_page") # <=
),
navContent(
id = "pages",
navPane(
id = "home_page",
h1("Home")
),
navPane(
id = "about_page",
h1("About")
)
)
)
server <- function(input, output) { }
shinyApp(ui, server)
I have revised the API. The argument is now actions and there are explicit helper functions for possible actions.
Implicit value and id matching
Without names showTarget(X) will show a nav pane with X when a choice with value X is selected.
navInput(
..,
actions = c(
showTarget("home"),
showTarget("about")
)
)
Explicit value and id matching
When named Y = showTarget(X) will show a nav pane with id X when a choice with value Y is selected.
navInput(
..,
actions = c(
home = showTarget("home"),
about = showTarget("about")
)
)
To make calling the correct plugin much easier I have switched from showTarget() to showNavTarget().
I am unsure how actions will interact with updating an input. I think selecting new values must trigger any corresponding actions or an application could quickly get out of sync.