闪亮的renderUI SelectInput不会更新

时间:2015-08-04 19:36:39

标签: r shiny

我尝试根据selectInput更新textInput中显示的值。我最初在输出$ text中没有if-else语句,但基于其他问题的建议,添加了它,但它仍然没有用。然后我尝试了"Shiny renderUI selectInput NULL"的解决方案,但那也没有用。

来自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])
    }
  })

目前,&#34;价值&#34;在textInput中只是NULL。如何根据selectInput?

为textInput更新值

1 个答案:

答案 0 :(得分:1)

这是你想要的吗?

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))