I am trying to pass the "language" text to a placeholder in the textAreaInput
. I want to pass the input$selectLanguage
to the textArea
and the placeholder text to change depending on the language selected.
App:
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
selectInput("selectLanguage", "What language ?", choices = c("EN", "ES", "FR")),
textAreaInput(inputId = "desc", label = "Describe yourself in a few words", width = '100%', rows = 4, placeholder = "emailPlaceholder"),
)
# Define server logic required to draw a histogram
server <- function(input, output) {
########################## Add placeholder #############################
emailPlaceholder = reactive({
emailDescPlaceholder = paste("In ", input$selectLanguage, " write about yourself: ")
})
output$emailPlaceholder = renderText({
emailPlaceholder()
})
}
# Run the application
shinyApp(ui = ui, server = server)
Expected output:
In "EN" write about yourself:
In "ES" write about yourself:
In "FR" write about yourself:
Solution:
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
selectInput("selectLanguage", "What language ?", choices = c("EN", "ES", "FR")),
textAreaInput(inputId = "desc", label = "Describe yourself in a few words", width = '100%', rows = 4)
)
# Define server logic required to draw a histogram
server <- function(input, output, session) {
########################## Add placeholder #############################
observe({
updateTextAreaInput(session, "desc",
placeholder = paste("In ", input$selectLanguage, " write about yourself: ")
)
})
}
# Run the application
shinyApp(ui = ui, server = server)
CodePudding user response:
Use updateTextAreaInput()
with placeholder
parameter.
https://www.rdocumentation.org/packages/shiny/versions/1.7.3/topics/updateTextAreaInput
CodePudding user response:
This solved my issue:
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
selectInput("selectLanguage", "What language ?", choices = c("EN", "ES", "FR")),
textAreaInput(inputId = "desc", label = "Describe yourself in a few words", width = '100%', rows = 4)
)
# Define server logic required to draw a histogram
server <- function(input, output, session) {
########################## Add placeholder #############################
observe({
updateTextAreaInput(session, "desc",
placeholder = paste("In ", input$selectLanguage, " write about yourself: ")
)
})
}
# Run the application
shinyApp(ui = ui, server = server)