Access input$ at ui.R, possible?

I know input$radiobutton1 is supposed to be on the server side, and not ui.R.

Say for my case, if I have a radiobutton to choose different languages, e.g English or French.
What I need is when user toggle between those radiobutton, I need the texts to be changed on the ui.R. So how should code for this case?
Thanks.

if the ui is dynamic not static/fixed, use uiOutput as its placeholder, and provide renderUI code that dynamically constructs it, you can place a radiobutton in such a way.
https://shiny.rstudio.com/articles/dynamic-ui.html

alternatively, you can have a static initial radiobutton, in the normal way, but use an observeEvent that you use to call an updateRadioButtons() function call, to redefine something about the radiobutton

hmmm.. interesting.. say for my case, I need to toggle the text below:

fluidRow(column(2,h1('TexttobeToggled')))

how should I use that uiOutput?

library(shiny)

ui <- fluidPage(
  fluidRow(column(2,uiOutput("myheader")))
)

server <- function(input, output, session) {
  
  headertext <- reactive('TexttobeToggled')
  
  output$myheader <- renderUI({
    h1(headertext())
  })
}

shinyApp(ui, server)

Thanks for the code. Say I am using some kind of translation from https://appsilon.com/internationalization-of-shiny-apps-i18n/, so I would have something like this? But it seems to break the application.

library(shiny.i18n)
ui <- fluidPage(
  fluidRow(column(2,uiOutput("myheader")),
           column(2,column(2,radioButtons('language',"",choices = c("English"="english","Spanish"="spanish"),inline = TRUE)))
  )
)
server <- function(input, output, session) {
  i18n <- Translator$new(translation_json_path = "C:\\xxx\\JSON\\translation.json")
  headertext <- reactive(){
    if (input$language=="english"){
      i18n$set_translation_language("en")
    } else {
      i18n$set_translation_language("sp")
    }
    Test_translated <- i18n$t('Test')
  }
  
  output$myheader <- renderUI({
    h1(headertext())
  })
}
shinyApp(ui, server)

You can study https://shiny.rstudio.com/tutorial/written-tutorial/lesson6/ if you aren't familiar with reactives
The following is incorrect syntax

headertext <- reactive(){
         if (input$language=="english"){
               i18n$set_translation_language("en")
         } else {
              i18n$set_translation_language("sp")
         }
         Test_translated <- i18n$t('Test')
     }

rather

headertext <- reactive({
        if (input$language=="english"){
               i18n$set_translation_language("en")
         } else {
              i18n$set_translation_language("sp")
         }
         i18n$t('Test')
     })

Though this assumes you are using Translator correctly , which I'm not familiar with..

It is working now, thank you very much for your help. :slight_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.