2

I am trying to build a simple shinyapp as part of learning shiny.

Problem: I have a conditionalPanel located in sidebarPanel, which I would like to reset in case the condition changes back.

I have found similar questions on StackOverflow here and here. Both threads indicated that the solution was to add id; however, it did not solve my problem.

The shinyapp works by calculating a nomogram-score, which can be used to predict overall survival. It contains four components:

(1) n.fjernet is the number of lymph nodes removed on the cervical neck

(2) n.sygdom is the number of lymph nodes with evidence of cancer metastises.

(3) ecs is extracapsular spread (of metastises, i.e. the metastises penetrating one or more of the lymph nodes) in n.sygdom. Therefore, this radioButtion() can only be available if n.sygdom ≥ 1

(4) contra.pos is whether the spread (of metastises) includes the uni- or contralateral side of the neck. Therefore, this radioButtion() can only be available if n.sygdom ≥ 1.

So, currently, the radioButtons("ecs") and radioButtons("contra.pos") activates if n.sygdom ≥ 1. If the user changes back to n.sygdom==0, the radioButtions() disappear. But, if n.sygdom ≥ 1 is chosen again, the radioButtons() activates at the same input-value as when they were deactivated by n.sygdom==0.

Please, how can I change this script so that the input from the radioButtons() reset if switched off?

I tried (and numerous different id-names)

sidebarPanel(id="n_sygdom", ...),
      sliderInput("n_fjernet", ... )

Script:

library(shiny)
library(survminer)


ui <- fluidPage(
  titlePanel("Survival Curve of individualized pN-staging\n"),
  sidebarLayout(
    sidebarPanel(id="",
      sliderInput("n_fjernet", "Lymph Nodal Yield", min = 2, max = 120, value = 40),
      sliderInput("n_sygdom", "Number of positive lymph nodes", min = 0, max = 40, value = 0),
      conditionalPanel(
        condition = "input.n_sygdom >= 1",
        radioButtons("ecs", "Extracapsular extension", c("No","Yes")),
        radioButtons("contra.pos", "Neck involvement", c("Contra.","Ipsi.")
        )
      ),
      verbatimTextOutput("out.score"),
      verbatimTextOutput("out.score.group")
    ),
    mainPanel(
      plotOutput("surv_plot")
    )
  )
)



server <- function(input, output, session) {

  calc_score <- reactive({
    round(nom$ecs$points[nom$ecs$ecs==input$ecs] +
          nom$contra.pos$points[nom$contra.pos$contra.pos==input$contra.pos] +
          nom$n_fjernet$points[nom$n_fjernet$n_fjernet==input$n_fjernet] +
          nom$n_sygdom$points[nom$n_sygdom$n_sygdom==input$n_sygdom], digits=1)
  })

  observe(
    updateSliderInput(
      session = session,
      inputId = "n_sygdom",
      max = min(40, input$n_fjernet),
      value = min(input$n_fjernet, input$n_sygdom)
    )
  )

  calc_score_group <- function(score) {
    cut(score, c(0,35.9,55.2,70.0,83.3,Inf), include.lowest = TRUE, labels = c("1","2","3","4","5"))
  }

  fit_data <- reactive({
    p %>% filter(score.group == as.numeric(calc_score_group(calc_score())))
  })

  fit_model <- reactive({
    survfit(Surv(os.neck, mors) ~ 1, data = fit_data())
  })



  output$out.score <- renderText(calc_score())
  output$out.score.group <- renderText(calc_score_group(calc_score()))

  output$surv_plot <- renderPlot({
    ggsurvplot(
      fit_model(),                     
      data = fit_data(), 
      risk.table = TRUE, 
      pval = F,      
      pval.coord = c(0, 0.25),
      conf.int = T,         
      size=1,                    
      xlim = c(0,60),
      conf.int.alpha=c(0.2),
      break.x.by = 6,    
      xlab="Time in months",
      ylab="Probability of overall survival",
      ggtheme = theme,             
      surv.median.line = "v",
      ylim=c(0,1),
      palette="#2C77BF",
      tables.theme=theme,
      legend.title=paste("Score group", calc_score_group(calc_score())),
      surv.scale="percent",
      tables.col="strata",
      risk.table.col = "strata",
      risk.table.y.text = FALSE,
      tables.y.text = FALSE)
  })


}

shinyApp(ui, server)

My data

p <- structure(list(contra.pos = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L,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L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 
    2L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 
    2L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 
    1L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 
    1L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 
    1L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 2L, 2L, 2L, 1L, 2L
    ), .Label = c("No", "Yes"), class = "factor"), n.fjernet = c(22L, 
    61L, 50L, 47L, 30L, 60L, 82L, 60L, 33L, 67L, 35L, 56L, 15L, 
    37L, 44L, 124L, 41L, 30L, 31L, 35L, 36L, 28L, 39L, 54L, 25L, 
    27L, 69L, 53L, 24L, 33L, 52L, 77L, 51L, 7L, 22L, 53L, 26L, 
    58L, 28L, 83L, 39L, 15L, 37L, 27L, 9L, 17L, 32L, 26L, 44L, 
    52L, 22L, 62L, 53L, 68L, 52L, 38L, 50L, 21L, 41L, 74L, 15L, 
    26L, 36L, 37L, 34L, 22L, 31L, 53L, 13L, 44L, 43L, 51L, 20L, 
    21L, 63L, 40L, 25L, 17L, 43L, 47L, 35L, 21L, 4L, 23L, 35L, 
    50L, 69L, 24L, 38L, 45L, 37L, 35L, 25L, 19L, 43L, 19L, 33L, 
    38L, 50L, 21L, 40L, 100L, 45L, 53L, 41L, 7L, 75L, 48L, 20L, 
    11L, 72L, 37L, 34L, 70L, 20L, 47L, 44L, 45L, 48L, 23L, 27L, 
    24L, 39L, 9L, 34L, 22L, 89L, 40L, 35L, 34L, 61L, 28L, 27L, 
    62L, 47L, 13L, 20L, 9L, 27L, 38L, 44L, 15L, 33L, 65L, 31L, 
    49L, 53L, 15L, 26L, 17L, 24L, 20L, 25L, 12L, 34L, 22L, 27L, 
    14L, 27L, 31L, 26L, 15L, 16L, 30L, 19L, 51L, 12L, 33L, 68L, 
    26L, 20L, 34L, 31L, 7L, 76L, 7L, 24L, 36L, 22L, 27L, 35L, 
    64L, 18L, 38L, 10L, 27L, 26L, 47L, 15L, 30L, 30L, 21L, 31L, 
    14L, 14L, 22L, 28L, 13L, 17L, 16L, 7L, 11L, 37L, 55L, 13L, 
    26L, 17L, 12L, 44L, 58L, 20L, 28L, 7L, 24L, 10L, 42L, 39L, 
    14L, 31L, 49L), n.sygdom = c(1L, 2L, 1L, 3L, 1L, 0L, 3L, 
    0L, 2L, 1L, 4L, 4L, 1L, 0L, 2L, 2L, 1L, 0L, 0L, 4L, 0L, 0L, 
    1L, 1L, 0L, 1L, 4L, 3L, 1L, 0L, 8L, 1L, 1L, 1L, 1L, 1L, 0L, 
    1L, 2L, 1L, 0L, 2L, 1L, 0L, 2L, 0L, 3L, 0L, 1L, 1L, 1L, 2L, 
    0L, 3L, 2L, 1L, 0L, 0L, 0L, 2L, 0L, 3L, 0L, 0L, 0L, 1L, 1L, 
    0L, 0L, 1L, 4L, 0L, 0L, 2L, 2L, 1L, 1L, 0L, 0L, 3L, 1L, 6L, 
    0L, 0L, 0L, 3L, 2L, 2L, 4L, 0L, 3L, 27L, 0L, 2L, 1L, 0L, 
    0L, 1L, 1L, 2L, 2L, 5L, 1L, 0L, 0L, 1L, 0L, 5L, 0L, 0L, 2L, 
    10L, 0L, 6L, 2L, 1L, 2L, 0L, 0L, 0L, 0L, 4L, 0L, 0L, 1L, 
    5L, 2L, 2L, 1L, 2L, 1L, 0L, 0L, 1L, 13L, 0L, 1L, 0L, 1L, 
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 0L, 0L, 0L, 
    0L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 
    0L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 1L, 
    0L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 1L, 1L, 
    1L, 0L, 0L, 1L, 0L, 1L), os.neck = c(9.63, 7.03, 9.17, 10.48, 
    7.69, 15.18, 13.5, 16.33, 15.31, 12.09, 12.35, 22.28, 15.77, 
    14.39, 10.02, 14.52, 8.44, 23.82, 5.95, 3.78, 19.32, 20.14, 
    15.51, 19.78, 12.98, 32.92, 9.76, 5.65, 30.75, 2.79, 33.58, 
    27.53, 27.63, 14.62, 29.17, 25.4, 18.43, 5.29, 30.75, 28.48, 
    14.69, 13.14, 6.6, 26.81, 40.74, 11.63, 13.31, 10.41, 9.56, 
    17.51, 35.78, 35.75, 37.62, 33.25, 36.96, 34.56, 40.05, 41.26, 
    24.34, 37.49, 40.94, 24.11, 39.33, 11.24, 39.1, 19.75, 38.93, 
    39.36, 36.34, 48, 29.17, 47.93, 3.68, 24.21, 46.36, 49.12, 
    50.96, 14.16, 54.01, 19.88, 50.86, 1.87, 54.24, 13.93, 11.6, 
    10.05, 23.1, 62.78, 12.58, 39, 59.83, 6.77, 60.39, 18.46, 
    61.77, 58.41, 49.45, 64.26, 2.4, 26.51, 58.94, 69.91, 64.66, 
    55.56, 46.55, 29.63, 55.66, 19.68, 7.62, 2.73, 17.77, 10.12, 
    9.95, 74.22, 57.3, 58.94, 27.01, 34.23, 78.82, 27.2, 83.02, 
    76.68, 58.15, 22.18, 14.49, 3.91, 25.92, 74.64, 66.83, 70.74, 
    38.08, 7.69, 74.55, 49.94, 11.1, 88.54, 6.44, 79.54, 80.82, 
    70.83, 12.91, 81.25, 17.38, 29.96, 94.72, 73.53, 72.54, 1.35, 
    89.69, 62.85, 7.62, 93.27, 5.09, 51.25, 62, 55.33, 44.62, 
    56.94, 94.55, 88.61, 32.46, 11.04, 16.53, 100.04, 24.74, 
    24.54, 5.75, 59.83, 59.83, 77.77, 92.78, 49.58, 91.2, 1.18, 
    18.92, 6.34, 32.46, 72.41, 105.82, 1.84, 12.78, 57.56, 59.14, 
    104.08, 15.54, 117.75, 4.27, 67.61, 19.78, 112.49, 53.59, 
    107.01, 47.57, 9.46, 53.59, 46.46, 57.33, 18.76, 82.04, 13.67, 
    67.45, 28.98, 21.19, 121.4, 91.07, 50.83, 121.72, 123.04, 
    6.31, 123.5, 58.68, 9.56, 34.1, 90.48, 71.1, 11.33, 65.35, 
    54.21, 34.99, 62.06), score = c(47.16, 47.55, 39.27, 72.23, 
    44.91, 25.74, 62.36, 25.74, 55.44, 34.48, 82.32, 76.4, 60.64, 
    32.22, 52.34, 36.13, 41.81, 34.2, 33.91, 65.66, 32.51, 34.76, 
    42.37, 38.14, 35.61, 45.75, 61.23, 59.04, 46.6, 33.35, 84.05, 
    26.5, 38.99, 62.89, 47.16, 38.42, 35.32, 37.01, 56.85, 29.96, 
    31.66, 60.52, 42.93, 35.04, 62.21, 37.86, 64.96, 35.32, 40.96, 
    38.71, 47.16, 58.77, 27.71, 54.81, 50.09, 42.65, 28.56, 36.73, 
    31.1, 43.88, 38.43, 78.15, 32.51, 32.22, 33.07, 47.16, 44.63, 
    27.71, 38.99, 40.96, 68.56, 28.28, 37.02, 58.83, 58.48, 42.09, 
    46.32, 37.86, 30.53, 60.73, 55, 77.47, 41.53, 36.17, 32.79, 
    71.38, 56.79, 57.98, 76.32, 29.97, 63.55, 123.86, 35.61, 
    59.39, 41.24, 37.3, 33.35, 37.5, 39.27, 58.83, 53.47, 52.02, 
    35.52, 27.71, 31.1, 51.39, 21.51, 83.34, 37.02, 39.55, 50.79, 
    91.42, 33.07, 63.65, 70.61, 51.62, 52.34, 29.97, 29.12, 36.17, 
    35.04, 85.42, 31.66, 40.12, 55.28, 90.67, 51.15, 53.47, 43.5, 
    55.16, 47.67, 34.76, 35.04, 35.89, 98.47, 38.99, 59.23, 40.12, 
    57.25, 31.94, 52.46, 49.14, 33.35, 92.46, 33.91, 50.93, 49.8, 
    38.43, 57.42, 37.86, 35.89, 47.73, 57.82, 39.27, 33.07, 36.45, 
    57.13, 70.03, 57.25, 71.95, 35.32, 60.64, 38.14, 71.76, 91.52, 
    61.15, 39.27, 33.35, 56.36, 35.32, 47.73, 43.78, 33.91, 62.77, 
    75.44, 51.39, 78.71, 78.39, 47.16, 45.75, 55, 24.61, 37.58, 
    42.65, 62.05, 35.04, 35.32, 51.62, 38.43, 34.2, 34.2, 42.29, 
    33.91, 49.42, 60.8, 36.45, 56.97, 61.2, 37.86, 38.14, 40.68, 
    61.77, 54.43, 27.15, 49.7, 46.04, 60.07, 39.27, 130.25, 59.89, 
    37.02, 40.32, 40.68, 69.48, 39.84, 73.64, 53.87, 60.92, 71.95, 
    51.05), score.group = structure(c(2L, 2L, 2L, 4L, 2L, 1L, 
    3L, 1L, 3L, 1L, 4L, 4L, 3L, 1L, 2L, 2L, 2L, 1L, 1L, 3L, 1L, 
    1L, 2L, 2L, 1L, 2L, 3L, 3L, 2L, 1L, 5L, 1L, 2L, 3L, 2L, 2L, 
    1L, 2L, 3L, 1L, 1L, 3L, 2L, 1L, 3L, 2L, 3L, 1L, 2L, 2L, 2L, 
    3L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 4L, 1L, 1L, 1L, 2L, 
    2L, 1L, 2L, 2L, 3L, 1L, 2L, 3L, 3L, 2L, 2L, 2L, 1L, 3L, 2L, 
    4L, 2L, 2L, 1L, 4L, 3L, 3L, 4L, 1L, 3L, 5L, 1L, 3L, 2L, 2L, 
    1L, 2L, 2L, 3L, 2L, 2L, 1L, 1L, 1L, 2L, 1L, 5L, 2L, 2L, 2L, 
    5L, 1L, 3L, 4L, 2L, 2L, 1L, 1L, 2L, 1L, 5L, 1L, 2L, 3L, 5L, 
    2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 5L, 2L, 3L, 2L, 3L, 1L, 2L, 
    2L, 1L, 5L, 1L, 2L, 2L, 2L, 3L, 2L, 1L, 2L, 3L, 2L, 1L, 2L, 
    3L, 4L, 3L, 4L, 1L, 3L, 2L, 4L, 5L, 3L, 2L, 1L, 3L, 1L, 2L, 
    2L, 1L, 3L, 4L, 2L, 4L, 4L, 2L, 2L, 2L, 1L, 2L, 2L, 3L, 1L, 
    1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 3L, 2L, 3L, 3L, 2L, 2L, 2L, 
    3L, 2L, 1L, 2L, 2L, 3L, 2L, 5L, 3L, 2L, 2L, 2L, 3L, 2L, 4L, 
    2L, 3L, 4L, 2L), .Label = c("1", "2", "3", "4", "5"), class = "factor")), row.names = c(NA, 
220L), class = "data.frame")

And nomogram

nom <- structure(list(n.fjernet = structure(list(n.fjernet = c(2, 3, 
4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 
37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 
53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 
69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 
85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 
101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 
114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 
127, 128, 129, 130, 131, 132, 133), Xbeta = c(`1` = -0.0114560716414661, 
`2` = -0.0171841074621991, `3` = -0.0229121432829322, `4` = -0.0286401791036652, 
`5` = -0.0343682149243983, `6` = -0.0400962507451313, `7` = -0.0458242865658644, 
`8` = -0.0515523223865974, `9` = -0.0572803582073305, `10` = -0.0630083940280635, 
`11` = -0.0687364298487966, `12` = -0.0744644656695296, `13` = -0.0801925014902627, 
`14` = -0.0859205373109957, `15` = -0.0916485731317288, `16` = -0.0973766089524618, 
`17` = -0.103104644773195, `18` = -0.108832680593928, `19` = -0.114560716414661, 
`20` = -0.120288752235394, `21` = -0.126016788056127, `22` = -0.13174482387686, 
`23` = -0.137472859697593, `24` = -0.143200895518326, `25` = -0.148928931339059, 
`26` = -0.154656967159792, `27` = -0.160385002980525, `28` = -0.166113038801258, 
`29` = -0.171841074621991, `30` = -0.177569110442725, `31` = -0.183297146263458, 
`32` = -0.189025182084191, `33` = -0.194753217904924, `34` = -0.200481253725657, 
`35` = -0.20620928954639, `36` = -0.211937325367123, `37` = -0.217665361187856, 
`38` = -0.223393397008589, `39` = -0.229121432829322, `40` = -0.234849468650055, 
`41` = -0.240577504470788, `42` = -0.246305540291521, `43` = -0.252033576112254, 
`44` = -0.257761611932987, `45` = -0.26348964775372, `46` = -0.269217683574453, 
`47` = -0.274945719395186, `48` = -0.280673755215919, `49` = -0.286401791036652, 
`50` = -0.292129826857386, `51` = -0.297857862678119, `52` = -0.303585898498852, 
`53` = -0.309313934319585, `54` = -0.315041970140318, `55` = -0.320770005961051, 
`56` = -0.326498041781784, `57` = -0.332226077602517, `58` = -0.33795411342325, 
`59` = -0.343682149243983, `60` = -0.349410185064716, `61` = -0.355138220885449, 
`62` = -0.360866256706182, `63` = -0.366594292526915, `64` = -0.372322328347648, 
`65` = -0.378050364168381, `66` = -0.383778399989114, `67` = -0.389506435809847, 
`68` = -0.39523447163058, `69` = -0.400962507451313, `70` = -0.406690543272047, 
`71` = -0.41241857909278, `72` = -0.418146614913513, `73` = -0.423874650734246, 
`74` = -0.429602686554979, `75` = -0.435330722375712, `76` = -0.441058758196445, 
`77` = -0.446786794017178, `78` = -0.452514829837911, `79` = -0.458242865658644, 
`80` = -0.463970901479377, `81` = -0.46969893730011, `82` = -0.475426973120843, 
`83` = -0.481155008941576, `84` = -0.486883044762309, `85` = -0.492611080583042, 
`86` = -0.498339116403775, `87` = -0.504067152224508, `88` = -0.509795188045241, 
`89` = -0.515523223865974, `90` = -0.521251259686707, `91` = -0.526979295507441, 
`92` = -0.532707331328174, `93` = -0.538435367148907, `94` = -0.54416340296964, 
`95` = -0.549891438790373, `96` = -0.555619474611106, `97` = -0.561347510431839, 
`98` = -0.567075546252572, `99` = -0.572803582073305, `100` = -0.578531617894038, 
`101` = -0.584259653714771, `102` = -0.589987689535504, `103` = -0.595715725356237, 
`104` = -0.60144376117697, `105` = -0.607171796997703, `106` = -0.612899832818436, 
`107` = -0.618627868639169, `108` = -0.624355904459902, `109` = -0.630083940280635, 
`110` = -0.635811976101369, `111` = -0.641540011922102, `112` = -0.647268047742835, 
`113` = -0.652996083563568, `114` = -0.658724119384301, `115` = -0.664452155205034, 
`116` = -0.670180191025767, `117` = -0.6759082268465, `118` = -0.681636262667233, 
`119` = -0.687364298487966, `120` = -0.693092334308699, `121` = -0.698820370129432, 
`122` = -0.704548405950165, `123` = -0.710276441770898, `124` = -0.716004477591631, 
`125` = -0.721732513412364, `126` = -0.727460549233097, `127` = -0.73318858505383, 
`128` = -0.738916620874563, `129` = -0.744644656695296, `130` = -0.750372692516029, 
`131` = -0.756100728336763, `132` = -0.761828764157496), points = c(`1` = 27.84103949255, 
`2` = 27.6285124735229, `3` = 27.4159854544958, `4` = 27.2034584354687, 
`5` = 26.9909314164416, `6` = 26.7784043974145, `7` = 26.5658773783874, 
`8` = 26.3533503593603, `9` = 26.1408233403332, `10` = 25.9282963213061, 
`11` = 25.715769302279, `12` = 25.5032422832519, `13` = 25.2907152642248, 
`14` = 25.0781882451977, `15` = 24.8656612261706, `16` = 24.6531342071435, 
`17` = 24.4406071881164, `18` = 24.2280801690893, `19` = 24.0155531500622, 
`20` = 23.8030261310351, `21` = 23.590499112008, `22` = 23.3779720929809, 
`23` = 23.1654450739538, `24` = 22.9529180549267, `25` = 22.7403910358996, 
`26` = 22.5278640168725, `27` = 22.3153369978454, `28` = 22.1028099788183, 
`29` = 21.8902829597912, `30` = 21.6777559407641, `31` = 21.465228921737, 
`32` = 21.2527019027099, `33` = 21.0401748836828, `34` = 20.8276478646557, 
`35` = 20.6151208456286, `36` = 20.4025938266015, `37` = 20.1900668075744, 
`38` = 19.9775397885473, `39` = 19.7650127695202, `40` = 19.5524857504931, 
`41` = 19.339958731466, `42` = 19.1274317124389, `43` = 18.9149046934118, 
`44` = 18.7023776743847, `45` = 18.4898506553576, `46` = 18.2773236363305, 
`47` = 18.0647966173034, `48` = 17.8522695982763, `49` = 17.6397425792492, 
`50` = 17.4272155602221, `51` = 17.214688541195, `52` = 17.0021615221679, 
`53` = 16.7896345031408, `54` = 16.5771074841137, `55` = 16.3645804650866, 
`56` = 16.1520534460595, `57` = 15.9395264270324, `58` = 15.7269994080053, 
`59` = 15.5144723889782, `60` = 15.3019453699511, `61` = 15.089418350924, 
`62` = 14.8768913318969, `63` = 14.6643643128698, `64` = 14.4518372938427, 
`65` = 14.2393102748156, `66` = 14.0267832557885, `67` = 13.8142562367614, 
`68` = 13.6017292177343, `69` = 13.3892021987072, `70` = 13.1766751796801, 
`71` = 12.964148160653, `72` = 12.7516211416259, `73` = 12.5390941225988, 
`74` = 12.3265671035717, `75` = 12.1140400845446, `76` = 11.9015130655175, 
`77` = 11.6889860464904, `78` = 11.4764590274633, `79` = 11.2639320084362, 
`80` = 11.0514049894091, `81` = 10.838877970382, `82` = 10.6263509513549, 
`83` = 10.4138239323278, `84` = 10.2012969133007, `85` = 9.98876989427365, 
`86` = 9.77624287524655, `87` = 9.56371585621945, `88` = 9.35118883719235, 
`89` = 9.13866181816525, `90` = 8.92613479913816, `91` = 8.71360778011105, 
`92` = 8.50108076108396, `93` = 8.28855374205686, `94` = 8.07602672302976, 
`95` = 7.86349970400266, `96` = 7.65097268497556, `97` = 7.43844566594846, 
`98` = 7.22591864692136, `99` = 7.01339162789426, `100` = 6.80086460886717, 
`101` = 6.58833758984007, `102` = 6.37581057081297, `103` = 6.16328355178587, 
`104` = 5.95075653275877, `105` = 5.73822951373167, `106` = 5.52570249470457, 
`107` = 5.31317547567747, `108` = 5.10064845665037, `109` = 4.88812143762328, 
`110` = 4.67559441859617, `111` = 4.46306739956908, `112` = 4.25054038054198, 
`113` = 4.03801336151488, `114` = 3.82548634248778, `115` = 3.61295932346068, 
`116` = 3.40043230443358, `117` = 3.18790528540648, `118` = 2.97537826637939, 
`119` = 2.76285124735228, `120` = 2.55032422832519, `121` = 2.33779720929809, 
`122` = 2.12527019027099, `123` = 1.91274317124389, `124` = 1.70021615221679, 
`125` = 1.48768913318969, `126` = 1.27516211416259, `127` = 1.06263509513549, 
`128` = 0.850108076108397, `129` = 0.637581057081296, `130` = 0.425054038054198, 
`131` = 0.212527019027097, `132` = 0)), info = list(nfun = 3L, 
    predictor = "n.fjernet", effect.name = "n.fjernet", type = "main")), 
    n.sygdom = structure(list(n.sygdom = c(0, 1, 2, 3, 4, 5, 
    6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 
    22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 
    37, 38, 39, 40), Xbeta = c(`133` = 0, `134` = 0.32236136668714, 
    `135` = 0.648650531337351, `136` = 0.909274081797897, `137` = 1.09719119915252, 
    `138` = 1.2269431700224, `139` = 1.31307128102872, `140` = 1.37011681879267, 
    `141` = 1.41262106993544, `142` = 1.452701773308, `143` = 1.49278247668057, 
    `144` = 1.53286318005315, `145` = 1.57294388342572, `146` = 1.61302458679829, 
    `147` = 1.65310529017085, `148` = 1.69318599354344, `149` = 1.733266696916, 
    `150` = 1.77334740028855, `151` = 1.81342810366113, `152` = 1.8535088070337, 
    `153` = 1.89358951040629, `154` = 1.93367021377884, `155` = 1.97375091715141, 
    `156` = 2.01383162052397, `157` = 2.05391232389658, `158` = 2.09399302726916, 
    `159` = 2.13407373064171, `160` = 2.17415443401433, `161` = 2.21423513738691, 
    `162` = 2.25431584075947, `163` = 2.29439654413205, `164` = 2.33447724750454, 
    `165` = 2.37455795087723, `166` = 2.41463865424957, `167` = 2.45471935762221, 
    `168` = 2.49480006099482, `169` = 2.53488076436739, `170` = 2.57496146774009, 
    `171` = 2.61504217111266, `172` = 2.65512287448523, `173` = 2.69520357785787
    ), points = c(`133` = 0, `134` = 11.9605572408505, `135` = 24.0668473679043, 
    `136` = 33.7367495824038, `137` = 40.7090287415156, `138` = 45.5232094563172, 
    `139` = 48.7188163378863, `140` = 50.8353739973004, `141` = 52.412407045637, 
    `142` = 53.8995193254604, `143` = 55.3866316052841, `144` = 56.8737438851078, 
    `145` = 58.3608561649314, `146` = 59.8479684447552, `147` = 61.3350807245785, 
    `148` = 62.8221930044026, `149` = 64.309305284226, `150` = 65.7964175640487, 
    `151` = 67.283529843873, `152` = 68.7706421236966, `153` = 70.257754403521, 
    `154` = 71.7448666833438, `155` = 73.2319789631674, `156` = 74.7190912429907, 
    `157` = 76.2062035228159, `158` = 77.6933158026398, `159` = 79.1804280824625, 
    `160` = 80.6675403622881, `161` = 82.1546526421122, `162` = 83.6417649219352, 
    `163` = 85.1288772017594, `164` = 86.6159894815798, `165` = 88.103101761408, 
    `166` = 89.5902140412232, `167` = 91.0773263210494, `168` = 92.5644386008743, 
    `169` = 94.0515508806979, `170` = 95.5386631605266, `171` = 97.0257754403502, 
    `172` = 98.5128877201739, `173` = 100)), info = list(nfun = 3L, 
        predictor = "n.sygdom", effect.name = "n.sygdom", type = "main")), 
    ecs = structure(list(ecs = c("No", "Yes"), Xbeta = c(`174` = 0, 
    `175` = 0.352802098746005), points = c(`174` = 0, `175` = 13.0899981598574
    )), info = list(nfun = 3L, predictor = "ecs", effect.name = "ecs", 
        type = "main")), contra.pos = structure(list(contra.pos = c("Ipsi.", 
    "Contra."), Xbeta = c(`176` = 0, `177` = -0.149053853083395
    ), points = c(`176` = 5.53033745977221, `177` = 0)), info = list(
        nfun = 3L, predictor = "contra.pos", effect.name = "contra.pos", 
        type = "main")), total.points = list(x = c(0, 10, 20, 
    30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140)), lp = list(
        x = c(8.59901355289166, 27.1504878870641, 45.7019622212365, 
        64.253436555409, 82.8049108895814, 101.356385223754, 
        119.907859557926, 138.459333892099), x.real = c(-1, -0.5, 
        0, 0.5, 1, 1.5, 2, 2.5)), `Probability of 1 year survival` = list(
        x = c(132.923978485611, 122.154519662532, 112.023605643525, 
        101.668496222993, 90.3441422980089, 77.0166169199793, 
        59.6149679036176, 31.771904926561), x.real = c(0.2, 0.3, 
        0.4, 0.5, 0.6, 0.7, 0.8, 0.9), fat = c("0.2", "0.3", 
        "0.4", "0.5", "0.6", "0.7", "0.8", "0.9"), which = c(FALSE, 
        TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE
        )), `Probability of 3 years survival` = list(x = c(111.455658509363, 
    98.1672795067317, 87.3978451509886, 77.2669361851509, 66.9118109221416, 
    55.5874579746061, 42.2599719337723, 24.8583283615229), x.real = c(0.1, 
    0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8), fat = c("0.1", "0.2", 
    "0.3", "0.4", "0.5", "0.6", "0.7", "0.8"), which = c(FALSE, 
    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE)), 
    `Probability of 5 years survival` = list(x = c(96.3366217164868, 
    83.0483098712202, 72.2788509036931, 62.1479468853665, 51.7928216700398, 
    40.468478298201, 27.1409533137375, 9.73931852863156), x.real = c(0.1, 
    0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8), fat = c("0.1", "0.2", 
    "0.3", "0.4", "0.5", "0.6", "0.7", "0.8"), which = c(FALSE, 
    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE))), info = list(
    fun = list(function (x) 
    surv(12, x), function (x) 
    surv(36, x), function (x) 
    surv(60, x)), lp = TRUE, lp.at = c(-1, -0.5, 0, 0.5, 1, 1.5, 
    2, 2.5), discrete = c(n.fjernet = FALSE, n.sygdom = FALSE, 
    ecs = TRUE, contra.pos = TRUE, studie = TRUE), funlabel = c("Probability of 1 year survival", 
    "Probability of 3 years survival", "Probability of 5 years survival"
    ), fun.at = NULL, fun.lp.at = NULL, Abbrev = list(), minlength = 4, 
    conf.int = FALSE, R = structure(c(-0.761828764157496, -0.0114560716414661, 
    0, 2.69520357785787, 0, 0.352802098746005, -0.149053853083395, 
    0), .Dim = c(2L, 4L), .Dimnames = list(NULL, c("n.fjernet", 
    "n.sygdom", "ecs", "contra.pos"))), sc = 37.1029486683449, 
    maxscale = 100, Intercept = -1.23176092093802, nint = 10, 
    space.used = c(main = 4, ia = 0)), class = "nomogram")
bretauv
  • 7,756
  • 2
  • 20
  • 57
cmirian
  • 2,572
  • 3
  • 19
  • 59

1 Answers1

1

@cmirian - nice to see you are making progress.

You could follow the first link you provided to reset your radio buttons, but in your case this might be a simpler solution.

You can detect the event when your slider changes for n_sygdom, and store the most recent value as a reactive value. Then, whenever you have 1 or more lymph nodes positive, and the most recent value for this input was 0, you can use updateRadioButtons to reset the buttons to original state.

Try adding the following to your server function:

rvs <- reactiveValues(n_sygdom = 0)

observeEvent(input$n_sygdom, {
  if (input$n_sygdom >= 1 && rvs$n_sygdom == 0) {
    updateRadioButtons(session, "ecs", selected = "No")
    updateRadioButtons(session, "contra.pos", selected = "Contra.")
  }
  rvs$n_sygdom <- input$n_sygdom
})

Edit: To ensure that the score is calculated correctly after input$n_sygdom returns to zero, reset the radio buttons in that case. You can change your if statement to:

if (input$n_sygdom == 0)

And you wouldn’t need reactive values at all.

Ben
  • 28,684
  • 5
  • 23
  • 45
  • Yes - thank you so much - really appreciated! It is a nice solution. Still a minor issue: the app still needs to reset `ecs` and `contra.pos`. Try this: `n_fjernet==40` + `n_sygdom==0` gives a score of `x`. If you change `n_fjernet==40`,`n_sygdom==1` and `ecs=="yes`, then the score is `x + n_sygdom==1 + ecs=="yes"`. Changing back to `n_fjernet==40` and `n_sygdom==0`, then the score still includes `ecs` and now equals `x + ecs=="yes"`. `ecs` may only equal "yes" in case of `n_sygdom >= 1`. Please, could you update the answer so that the `conditionalPanel()` completely resets if `n_sygdom==0`? – cmirian Apr 04 '20 at 10:54
  • And please, in case you could update the answer, keep the current answer too. It is a really nice one and I have included it too. – cmirian Apr 04 '20 at 10:55
  • 1
    I see. You can check when `input$n_sygdom` is zero and reset the radio buttons for that case as well. See edited answer and let me know if this works. – Ben Apr 04 '20 at 11:37
  • 1
    Yes! That did it, and I can see that expanding the `if`-statement is a really logical and straightforward solution. I learned from that. Thank you so much! Until next time :) – cmirian Apr 04 '20 at 11:45
  • 1
    You can simplify further to only check if input$n_sygdom is zero too - looks like similar behavior. – Ben Apr 04 '20 at 14:26