Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input actions #166

Open
nteetor opened this issue Aug 29, 2019 · 3 comments
Open

Input actions #166

nteetor opened this issue Aug 29, 2019 · 3 comments
Labels

Comments

@nteetor
Copy link
Owner

nteetor commented Aug 29, 2019

!! 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)
nteetor pushed a commit that referenced this issue Aug 29, 2019
* Nav inputs may trigger nav panes with the `targets` argument (#166)
@nteetor nteetor changed the title Allow inputs to target and trigger navs and other plugins Input actions Sep 2, 2019
@nteetor
Copy link
Owner Author

nteetor commented Sep 2, 2019

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")
  )
)

nteetor pushed a commit that referenced this issue Sep 3, 2019
* The targetting feature is now better named `actions`. (#166)
nteetor pushed a commit that referenced this issue Sep 6, 2019
* Use `showNavTarget()` and `hideNavTarget()` with a reactive input to
  change nav panes anywhere in an application (#166)
@nteetor
Copy link
Owner Author

nteetor commented Sep 6, 2019

To make calling the correct plugin much easier I have switched from showTarget() to showNavTarget().

@nteetor
Copy link
Owner Author

nteetor commented Sep 6, 2019

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.

nteetor pushed a commit that referenced this issue Nov 27, 2019
* Nav inputs may trigger nav panes with the `targets` argument (#166)
nteetor pushed a commit that referenced this issue Nov 27, 2019
* The targetting feature is now better named `actions`. (#166)
nteetor pushed a commit that referenced this issue Nov 27, 2019
* Use `showNavTarget()` and `hideNavTarget()` with a reactive input to
  change nav panes anywhere in an application (#166)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant