You are currently browsing Bárbara Borges Ribeiro’s articles.
Shinydashboard 0.6.0 is now on CRAN! This release of shinydashboard was aimed at both fixing bugs and also bringing the package up to speed with users’ requests and Shiny itself (especially fully bringing bookmarkable state to shinydashboard’s sidebar). In addition to bug fixes and new features, we also added a new “Behavior” section to the shinydashboard website to explain this release’s two biggest new features, and also to provide users with more material about shinydashboard-specific behavior.
Sidebar
This release introduces two new sidebar inputs. One of these inputs reports whether the sidebar is collapsed or expanded, and the other input reports which (if any) menu item in the side bar is expanded. In the screenshot below, the Charts tab is expanded.
These inputs are unusual since they’re automatically available without you needing to declare them, and they have a fixed name. The first input is accessible via input$sidebarCollapsed
and can have only two values: TRUE
, which indicates that the sidebar is collapsed, and FALSE
, which indicates that it is expanded (default).
The second input is accessible via input$sidebarItemExpanded
. If no menuItem()
in the sidebar is currently expanded, the value of this input is NULL
. Otherwise, input$sidebarItemExpanded
holds the value of the expandedName
of whichever menuItem()
is currently expanded (expandedName
is a new argument to menuItem()
; if none is provided, shinydashboard creates a sensible default).
Full changes
As usual, you can view the full changelog for shinydashboard in the NEWS file.
Shiny 1.0.1 is now available on CRAN! This release primarily includes bug fixes and minor new features.
The most notable additions in this version of Shiny are the introduction of the reactiveVal()
function (like reactiveValues()
, but it only stores a single value), and that the choices of radioButtons()
and checkboxGroupInput()
can now contain HTML content instead of just plain text. We’ve also added compatibility for the development version of ggplot2
.
Breaking changes
We unintentionally introduced a minor breaking change in that checkboxGroupInput
used to accept choices = NULL
to create an empty input. With Shiny 1.0.1, this throws an error; using choices = character(0)
works. We intend to eliminate this breakage in Shiny 1.0.2.
Update (4/20/2017): This has now been fixed in Shiny 1.0.2, currently available on CRAN.
Also, the selected
argument for radioButtons
, checkboxGroupInput
, and selectInput
once upon a time accepted the name of a choice, instead of the value of a choice; this behavior has been deprecated with a warning for several years now, and in Shiny 1.0.1 it is no longer supported at all.
Storing single reactive values with reactiveVal
The reactiveValues
object has been a part of Shiny since the earliest betas. It acts like a reactive version of an environment or named list, in that you can store and retrieve values using names:
rv <- reactiveValues(clicks = 0)
observeEvent(input$button, {
currentValue <- rv$clicks
rv$clicks <- currentValue + 1
})
If you only have a single value to store, though, it’s a little awkward that you have to use a data structure designed for multiple values.
With the new reactiveVal
function, you can now create a reactive object for a single variable:
clicks <- reactiveVal(0)
observeEvent(input$button, {
currentValue <- clicks()
clicks(currentValue + 1)
})
As you can see in this example, you can read the value by calling it like a function with no arguments; and you set the value by calling it with one argument.
This has the added benefit that you can easily pass the clicks
object to another function or module (no need to wrap it in a reactive()
).
More flexible radioButtons
and checkboxGroupInput
It’s now possible to create radio button and checkbox inputs with arbitrary HTML as labels. To do so, however, you need to pass different arguments to the functions. Now, when creating (or updating) either of radioButtons()
or checkboxGroupInput()
, you can specify the options in one of two (mutually exclusive) ways:
- What we’ve always had:
Use thechoices
argument, which must be a vector or list. The names of each element are displayed in the app UI as labels (i.e. what the user sees in your app), and the values are used for computation (i.e. the value is what’s returned byinput$rd
, whererd
is aradioButtons()
input). If the vector (or list) is unnamed, the values provided are used for both the UI labels and the server values. - What’s new and allows HTML:
Use both thechoiceNames
and thechoiceValues
arguments, each of which must be an unnamed vector or list (and both must have the same length). The elements inchoiceValues
must still be plain text (these are the values used for computation). But the elements inchoiceNames
(the UI labels) can be constructed out of HTML, either using theHTML()
function, or an HTML tag generation function, liketags$img()
andicon()
.
Here’s an example app that demos the new functionality (in this case, we have a checkboxGroupInput()
whose labels include the flag of the country they correspond to):
ggplot2
> 2.2.1 compatibility
The development version of ggplot2
has some changes that break compatibility with earlier versions of Shiny. The fixes in Shiny 1.0.1 will allow it to work with any version of ggplot2
.
A note on Shiny v1.0.0
In January of this year, we quietly released Shiny 1.0.0 to CRAN. A lot of work went into that release, but other than minor bug fixes and features, it was mostly laying the foundation for some important features that will arrive in the coming months. So if you’re wondering if you missed the blog post for Shiny 1.0.0, you didn’t.
Full changes
As always, you can view the full changelog for Shiny 1.0.1 (and 1.0.0!) in our NEWS.md file.