0

I have two boxes, and I would like to select one of the boxes, I would need to select one box and the other should be deselected. Here is what I am trying. I do not understand why its not changing colors and update the radiobuttons.

The boxes are being selected, but there is a problem with updating the status color and the text that I would like to update in the box.

library(shiny)

frow_quiz <- fluidRow(useShinyjs()
                      ,h1('This is the applications pages')
                      ,materialSwitch(inputId = 'enable', status = "default", inline = FALSE, right = TRUE) # onLabel = 'Enable', offLabel = 'Disabel',
                      ,uiOutput('box_left')
                      ,uiOutput('box_right')
                      # ,uiOutput('initial_selection'))
)

UI

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(sidebarMenu(
    menuItem("choose Explantions", tabName = "quiz", icon = icon("th"), selected = T)
  )),
  dashboardBody(do.call(tabItems,c(list(tabItem(tabName = 'quiz', frow_quiz))
  )), skin = 'blue')
)

server

server <- function(input, output, session) {
  observeEvent(session,{
    updateSwitchInput(session, inputId = 'enable', value = FALSE)
    pat_temp_vec <<- vector()
    row_temp_vec <<- vector()
    selected <<- character(0)
    status_1 <<- 'primary'
    status_2 <<- 'primary'
  })
  
  observe({  
    input$choice_1
    input$choice_2
    output$box_left <- renderUI({
      box(title = radioButtons('choice_1', 'Method 1', choices = c('method 1'), selected = character(0))
          ,status = status_1
          ,solidHeader = T
          ,collapsible = F
          ,collapsed = F
          ,width = 6
          ,uiOutput('choice')
      )
    })
  })
  
  observe({
    input$choice_1
    input$choice_2
    output$box_right <- renderUI({
      box(title = radioButtons('choice_2', 'Method 2', choices = c('method 2'), selected = character(0))
          ,status = status_2
          ,solidHeader = T
          ,collapsible = F
          ,collapsed = F
          ,width = 6
          ,uiOutput('choice')
      )
    })
  })
  
  observeEvent(input$choice_1, {
    status_1 <<- 'success'
    status_2 <<- 'primary'
    selected <<- 'method 1'
    output$choice <- renderText(input$choice_1)
    updateRadioButtons(inputId = 'choice_2', selected = character(0))
    updateRadioButtons(inputId = 'choice_1', selected = 'method 1')
  })
  
  observeEvent(input$choice_2, {
    status_2 <<- 'success'
    status_1 <<- 'primary'
    selected <<- 'method 2'
    output$choice <- renderText(input$choice_2)
    updateRadioButtons(inputId = 'choice_1', selected = character(0))
    updateRadioButtons(inputId = 'choice_2', selected = 'method 2')
  })
}

APP

shinyApp(ui = ui, server = server)
sveer
  • 427
  • 3
  • 16

0 Answers0