R Shiny-我无法从我的selectInput动作中检索选定的输出值 [英] R Shiny -- I am unable to retrieve the selected output value from my selectInput action

查看:116
本文介绍了R Shiny-我无法从我的selectInput动作中检索选定的输出值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法从我的selectInput动作中检索选定的输出值. 向量选择和选择的列表已适当地插入到UI中,但input$Site_User_Override变量值始终为NULL.

I cannot seem to retrieve the selected output value from my selectInput action. The lists from the vectors choices and selected are appropriately inserted into the UI, but the input$Site_User_Override variable value is always NULL.

output$Site_Pick_User = renderUI({
    choices=as.list(Subset_List()$to_Select)
    selected = Site_Pick_Initial()
    selectInput("Site_User_Override", "Override Site_Pick:", choices=choices,
        selected=selected, multiple = FALSE, selectize = TRUE, width = NULL, size = NULL)
    })

我的单行向量Site_Pick_Initial()="Name5_1.9mi_S" Subset_List()的结构是标题和下面的五行.

My single row vector Site_Pick_Initial()="Name5_1.9mi_S" And the structure of Subset_List() is the heading and five rows below.

Name    STATE   lat lon Air_Miles   Bearing Rose    Rank    to_Select   Delta_Dir
Name1   NJ  42.3    -74 8.826   12.092  NNE 33  Name1_8.8mi_NNE 175.89
Name2   NJ  42.2    -74 2.690   14.615  NNE 27  Name2_2.7mi_NNE 173.37
Name3   NJ  42.3    -74 9.049   348.271 NNW 34  Name3_9.0mi_NNW 160.29
Name4   NJ  42.2    -74 3.962   329.387 NNW 28  Name4_4.0mi_NNW 141.40
Name5   NJ  42.2    -74 1.868   187.983 S   21  Name5_1.9mi_S   0.00

如何获取input$Site_User_Override的值?上面的代码已简化;我需要在以后的计算和显示中使用input$Site_User_Override.

How can I retrieve the value of input$Site_User_Override? The code above is simplified; I need to use input$Site_User_Override in latter calculations and displays.

推荐答案

根据您的问题,以下代码应该等效,但可以正常工作.如果您尝试做的不同,请更新.

According to your question, the following code should be equivalent but it works totally fine. Please update if what you are trying to do is different.

library(shiny)

ui <- fluidPage(
  uiOutput("test"),
  verbatimTextOutput("debug")
)

data <- data.frame(
  Name = c("n1", "n2", "n3"), 
  to_Select = c("Name1_8.8mi_NNE", "Name4_4.0mi_NNW", "Name5_1.9mi_S"),
  stringsAsFactors = FALSE
)

server <- function(input, output, session) {
  output$test <- renderUI({
    selectInput(
      "Site_User_Override",
      "Override Site_Pick:",
      choices = data$to_Select,
      selected = "Name5_1.9mi_S"
    )
  })

  # input$Site_User_Override is updated and can be used elsewhere
  output$debug <- renderPrint({
    input$Site_User_Override
  })

}

shinyApp(ui, server)

这篇关于R Shiny-我无法从我的selectInput动作中检索选定的输出值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆