Â
These exercises are about using
reactivity in our apps.
Exercises for Shiny session 2
- Starting from the app made in question #3 of the exercises from
Session 1, add a sidebar so that it is present on all pages of the app
and add the following inputs:
- a slider input to control the number of bins in the histogram
- a dropdown that allows the user to choose which column to use for
the Kaplan Meier survival curve, allowing them to see the difference in
survival between the levels of that particular column.
- use the four columns used for the pie charts, and feel free to try
any more columns that might be of interest or have an impact of patient
survival.
- HINT: for the ‘survfit’ function with fitting the survival curve, to
use a variable in the formula, use the ‘as.formula’ function and ‘paste’
to make the formula, like this:
fit <- survfit(as.formula(paste0("surv_obj ~ ", input$survival_column)), data = data_in)

- Add a button to the sidebar and make it so the histogram and
survival curve don’t update with the new input values until the button
is pressed.
