I have run across this a few times and hope this might help someone. As Shiny apps get more complicated and you start to use Shiny modules you will likely run across use cases for using renderUI within modules. Sometimes it is desirable to be able to test these using packages like testthat.
However, you will run into a problem because of a missing session$ns.
Example adapted from: https://shiny.
Part One: Scope
This is going to be a fairly opinionated post about my not novel but recent revelations as to how I think Shiny apps should be formatted. By formatting I don’t mean UI formatting, code style, etc. I mean how one might organize, holistically, a Shiny app to help maximize readability, stability, and scalability. Again not novel, just me getting my thoughts “on paper’.
Before now my server() sections kind of looked like this: I am aware that it is possible to “modularize” a shiny app and there is good info on that from RStudio here and Steph Locke here.
My first scientific publication was published this month in PNAS: https://doi.org/10.1073/pnas.1801247115 and has been a long time coming. I began this project as an interim between my first and second rotations as a first-year PhD student, I am now in the second-half of my third year.
The manuscript took some time to prepare and apart from the usual: waiting for instrument time, repairs (LCQ used for initial derepilcation of desferrioxamines), etc.
See here for more about tidy tuesday: https://github.com/rfordatascience/tidytuesday
Read in data, remove punctuation from column names
inputData <- readxl::read_xlsx("data/4-19-18/global_mortality.xlsx")
names(inputData) <- str_trim(
Mean of each category grouped by country isn’t great, but for a tidy-tuesday it’ll do…
a2 <- inputData %>% group_by(country) %>% summarize_if(is.numeric,mean)
a <- a2 %>% select(4:34) %>% replace(is.na(.), 0)
principleComponents <- prcomp(a) %>%
Create data for t-SNE
# Get MNIST data for t-SNE
df_mnist <- createMNIST()
df_sampled <- df_mnist[sample(1:nrow(df_mnist), 1000), ]
mat_mnist <- as.matrix(df_sampled[ , !(colnames(df_sampled) == "Class")])
whichNumber <- as.character(df_sampled[ , (colnames(df_sampled) == "Class")])
# Going to do parallel t-SNE later (and data has to be created for each instance on Windows R parallel, so lets save the data as rds