1
votes

I have and simple example of the shiny app. Here I am testing the reaction of other elements to the change in the specific element.

ui.r

 library(shiny)
 shinyUI(fluidPage(

  titlePanel("SCORE CARD DEVELOPMENT PLATFORM"),
    navbarPage("ScoreDevApp",
         tabPanel("Settings",
                  fluidRow(column(2,
                                   actionButton("goButton_service", "Load    saved parameters",width=200)
                                  ,radioButtons("DB_switch"
                                              , "Select Data Source"
                                              ,c("Oracle"=1,"text file"=2)
                                  )
                  )             
                  )
         ),
         tabPanel("Download & Binning input data",
                  fluidRow(column(2,
                                  textInput("text","test")))),
         id="ScoreDevApp"
    )
  )
)

server.r

library(shiny)
library(shinyjs)


shinyServer(function(input, output, session) {

observeEvent(input$goButton_service, {
  updateRadioButtons(session
                   , "DB_switch"
                   , "Select Data Source"
                   ,c("Oracle"=1,"text file"=2)
                   , selected = 2
                   , inline = FALSE
  )
  if(input$DB_switch==2){
    updateTextInput(session,text,"test",value="testing")
   }

  })  
})

Pressing the button 'goButton_service' causes the update of radiobutton 'DB_switch' -> selected item is 2 in place of 1 (on default). Thats is done well.

But then I am going to check the value of radiobutton: if it is 2 then the string "testing" should have been passed to the textInput 'text' on the tabpanel 'Download & Binning input data'. However it is not performed. Need a help with it.

2

2 Answers

1
votes

Try the version below (I have removed the enable/disable code, it had no function). Your main error were the missing quotes around text.

library(shiny)
library(shinyjs)


shinyServer(function(input, output, session) {
  observe({
    if (input$DB_switch == "2") {
      updateTextInput(session, "text", value = "testing")
    }
  }
  )
  observeEvent(input$goButton_service, {
    updateRadioButtons(session
                       , "DB_switch"
                       , "Select Data Source"
                       ,c("Oracle"=1,"text file"=2)
                       , selected = 2
                       , inline = FALSE
    )
  })
})
0
votes

If you update textInput twice, as in the example below, it should solve your problem


Server

shinyServer(function(input, output, session) {

  observeEvent(input$goButton_service, {
    updateRadioButtons(session, "goButton_service", selected = 2)
    updateTextInput(session, "text", "test", value = "testing")
  }) 

  observe({
    if (input$DB_switch == 2) 
      updateTextInput(session, "text", "test", value = "testing")
  })

})