Revisión | b43b6e562e9b3fd6e97b03eb6f5c8436c9c61e78 (tree) |
---|---|
Tiempo | 2021-09-22 17:16:06 |
Autor | Lorenzo Isella <lorenzo.isella@gmai...> |
Commiter | Lorenzo Isella |
A code to use conditionalPanel with a condition from the server side.
@@ -0,0 +1,35 @@ | ||
1 | + | |
2 | + | |
3 | +### see https://stackoverflow.com/questions/41710455/shiny-conditionalpanel-set-condition-as-output-from-server | |
4 | + | |
5 | +library(shiny) | |
6 | +library(caret) | |
7 | + | |
8 | +ui <- fluidPage( | |
9 | + selectInput('dataset', 'Select Dataset', | |
10 | + list(GermanCredit = "GermanCredit", | |
11 | + cars = "cars")), | |
12 | + | |
13 | + conditionalPanel( | |
14 | + condition = "output.factorflag == true", | |
15 | + checkboxInput("UseFactor", "Add Factor Variable") | |
16 | + ) | |
17 | +) | |
18 | + | |
19 | + | |
20 | +server <- function(input, output) { | |
21 | + # Loading the dataset | |
22 | + df <- reactive({ | |
23 | + if(input$dataset == "GermanCredit"){ | |
24 | + data("GermanCredit") | |
25 | + GermanCredit | |
26 | + }else { | |
27 | + data("cars") | |
28 | + cars | |
29 | + } | |
30 | + }) | |
31 | + output$factorflag <- reactive("factor" %in% sapply(df(),class)) | |
32 | + outputOptions(output, "factorflag", suspendWhenHidden = FALSE) | |
33 | +} | |
34 | + | |
35 | +shinyApp(ui = ui, server = server) |