If I have a text area generated in my shiny app via renderUI from HTML, how would I access the text here from shiny?
Minimum reproducible example (how would I get the value typed in "mytextbox" into my input?):
library(shiny)
ui <- fluidPage(
htmlOutput("mytextbox")
)
server <- function(input, output){
output$mytextbox <- renderUI({
HTML('<html><textarea id="test" rows="3" cols="40"></textarea></html>')
})
}
shinyApp(ui, server)
The reason I'm asking this instead of using Shiny's text area input is because there are other js and html parts involved with this particular use case.
Thanks in advance!
Since you gave the element the id
of "test", you can check the input$test
value
ui <- fluidPage(
htmlOutput("mytextbox"),
textOutput("value")
)
server <- function(input, output){
output$mytextbox <- renderUI({
HTML('<textarea id="test" rows="3" cols="40"></textarea>')
})
output$value <- renderText(input$test)
}
shinyApp(ui, server)
You can render another UI and put the contents of 'test' inside. like @MrFlick pointed out, to access the content of the textarea element you need input$test.
library(shiny)
ui <- fluidPage(
mainPanel(
htmlOutput("mytextbox"),
uiOutput('inputs')
)
)
server <- function(input, output){
output$mytextbox <- renderUI({
HTML('<textarea id="test" rows="3" cols="40"></textarea>')
})
#render another UI
output$inputs <- renderUI({
tagList(textInput('text_test', '', input$test),
radioButtons('radio_bttn', 'First choice is the texarea content',
choices = c(input$test, 'another option')))
})
}
shinyApp(ui, server)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.