I'm working for the first time on a shiny app.
Based on an uploaded xlsx, the shiny app creates an reactive output called garnetRF()
. Based on the number of differently named samples in the uploaded xlsx, the app creates dynamic tabs in output$tabp
. In the tabs, the user can pick a color to be displayed for each sample. So far, so good.
Now, in the ouput$setting
I want to plot the results with the colors the user picked. Thus, my idea was to rename the sample levels by the picked color names (cls.0
). However, when performing the code as following, two level lists are produced and I don't understand why:
output$tabp <- renderUI({
req(garnetRF())
l = length(unique((garnetRF()[,"sample"])))
myTabs <- lapply(1:l, function(i) {
tabPanel(title = as.list(factor(unique(garnetRF()[,"sample"])))[[i]],
colourInput(paste0("col_", i), NULL, paste0("FF000", i), showColour = "background")
)
})
do.call(tabsetPanel, myTabs)
})
output$setting <- renderPlot({
l2 = length(unique((garnetRF()[,"sample"])))
cls.0 = factor((garnetRF()[,"sample"]))
levels(cls.0) = factor((sapply(1:l2, function(j){input[[paste0("col_", j)]]})))
print(levels(cls.0))
[1] "NULL"
[1] "#FF0001" "#FF0002" "#FF0003"
I would be grateful if anyone can help me with this....