0

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?

Community
  • 1
  • 1
Andrew
  • 839
  • 2
  • 7
  • 16

1 Answers1

1

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))
Pork Chop
  • 28,528
  • 5
  • 63
  • 77