I'm trying to update the value shown in textInput based on selectInput. I originally didn't have the if-else statement in output$text, but based on suggestions from other questions, added it, but it still didn't work. I then tried the solution from "Shiny renderUI selectInput NULL" , but that didn't work either.
Portion from server.r:
names <- list("A"=1, "B"=2, "C"=3, "D"=4, "E"=5, "F"=6, "G"=7, "H"=8, "I"=9)
# UI
output$view <- renderUI({
selectInput("viewTopic", "View Topic:", choices = names, selected = 1)
})
output$text <- renderUI({
if(is.null(input$viewTopic)){
return()
}else{
textInput("docTitle", label = "Topic Name:", value = names[input$viewTopic])
}
})
Currently, "value" in textInput is just NULL. How can I make the value for textInput update based on the selectInput?
Is this what you want?
rm(list = ls())
library(shiny)
names <- list("A"=1, "B"=2, "C"=3, "D"=4, "E"=5, "F"=6, "G"=7, "H"=8, "I"=9)
ui =(pageWithSidebar(
headerPanel("Test Shiny App"),
sidebarPanel(
selectInput("viewTopic", "View Topic:", choices = names, selected = 1),
#display dynamic UI
uiOutput("text")),
mainPanel()
))
server = function(input, output, session){
output$text <- renderUI({
textInput("docTitle", label = "Topic Name:", value = as.character(input$viewTopic))
})
}
runApp(list(ui = ui, server = 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.