- Use
renv::restore()to install the necessary dependencies. - Enable devmode and run the app.
- Take a look at
app/view/hello.R. - Add
hello$ui(ns("hello"))to the UI inmain.R. - Call
hello$server("hello")in the server inmain.R. - See if the app displayes "Hello" text.
Remember:
In the UI, the ID must be wrapped in ns(),
but in the server the namespace is applied automatically.
Learn more in
Modularizing Shiny app code
- Open
app/view/hello.R. - Add a
textInputwith label "What is your name?". - See if the input appears in the app.
- Add a
textOutputto the module UI. - Use
renderTextto greet the user with their name. - Type "Rhino" into the field and check if "Hello Rhino!" appears.
- Import the
logic/constandview/favoritesmodules inmain.R. - Add the
favoritesmodule to the app. Usecategory = "fruits"andchoices = const$fruits.
Add another instance of the favorites module.
Use category = "vegetables" and choices = const$vegetables this time.
- Add a
checkboxGroupInputto the UI of the favorites module. - Use the module parameters to define
choicesand a nicelabel.
- Copy over the files from
IMAGESdirectory toapp/static/img. - Fill in the missing part the in
images()function. You need to translate imagenameto path with/static/prefix. - Use
uiOutput()andrenderUI()to render theimages()based on user's selection.
- Define the
app/view/reversemodule. It should let the user type some text and display it with words in reverse order. - Fill in and use the
reverse_words()function fromapp/logic/reverse. - Add the module to the app.