Chapter 15 Modules

This chapter is in development...

Exercise 15.6.1

Example passing input$foo to reactive and it not working.

Solution. Solution

I don’t really know what this question is asking, but I think the point is to remember:

The main challenge with this sort of code is remembering when you use the reactive (e.g. x$value) vs. when you use its value (e.g. x$value()). Just remember that when passing an argument to a module, you want the module to react to the value changing which means that you have to pass the reactive, not it’s current value.

Where in this scenario, input$foo is analogous to x$value.

Exercise 15.6.2

Rewrite selectVarServer() so that both data and filter are reactive. Pair it with a app function that lets the user pick the dataset with the dataset module, a function with an inputSelect() that lets the user filter for numeric, character, or factor variables.

Solution. Solution

The modules datasetInput, datasetServer, and selectVarInput are the same, as well as the find_vars function.

We can start by creating selectFilterInput which has the filtering options as choices, and selectFilterServer which returns the filtering function given the selected choice string.

Now we can update the selectVarServer to take on an additional filter argument, and change the update function to not only observe when the data reactive changes but also our new filter widget changes. Lastly we pass in the filter reactive to the find_vars function.

Putting it together, we add our new module to the UI and server, and by saving the result of the selectFilterServer to filt we can pass that to the selectVarServer

Exercise 15.6.3

The following code defines output and server components of a module that takes a numeric input and produces a bulleted list of three summary statistics. Create an app function that allows you to experiment with it. The app function should take a data frame as input, and use numericVarSelectInput() to pick the variable to summarise.

Solution. Solution

We only need to add the code above to the selectVarApp() example in the book, and adapt the app code to include the summaryOutput instead of the verbatimTextOutput, and on the server side pass var to the summaryServer function instead of to the text output.

Exercise 15.6.4

The following module input provides a text control that lets you type a date in ISO8601 format (yyyy-mm-dd). Complete the module by providing a server function that uses output$error to display a message if the entered value is not a valid date. The module should return a Date object for valid dates. (Hint: use strptime(x, “%Y-%m-%d”) to parse the string; it will return NA if the value isn’t a valid date.)

Exercise 15.6.6

In wizardServer() verify that the namespacing has been set up correctly by using two or more wizards in a single add, and checking that you can navigate through each wizard independently.

Solution. Solution