• R/O
  • SSH

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisiónb43b6e562e9b3fd6e97b03eb6f5c8436c9c61e78 (tree)
Tiempo2021-09-22 17:16:06
AutorLorenzo Isella <lorenzo.isella@gmai...>
CommiterLorenzo Isella

Log Message

A code to use conditionalPanel with a condition from the server side.

Cambiar Resumen

Diferencia incremental

diff -r 9f60417bed38 -r b43b6e562e9b R-codes/shiny_condition_server_output.R
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/R-codes/shiny_condition_server_output.R Wed Sep 22 10:16:06 2021 +0200
@@ -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)