从selectInput的动态编号访问值

时间:2018-08-14 07:22:38

标签: r dynamic shiny

这个问题与我之前问的一个问题有关- dynamic number of selectInput

生成动态数量的selectInput选项后,如何访问这些值?上一个问题的相关代码是-

  library(shiny)
  ui = fluidPage(

  sidebarLayout(
    sidebarPanel(
      textInput(inputId = "number", label = "number of selectInput",value = 5)
    ),
    mainPanel(
      uiOutput(outputId = "putselect")
    )
  )
)
server = function(input,output){

  output$putselect = renderUI(
    if(input$number != 0 ){
      lapply(1:(input$number), function(i){
        selectInput(inputId = "i", label = paste0("input ",i), choices = c(2,(3)))
      })
    }
  )
}
shinyApp(ui = ui , server = server)

假设我想对所有“ input $ i”求和,我该怎么做?我无法访问“ input $ i”。

1 个答案:

答案 0 :(得分:0)

以下是一种可能的解决方案。请注意,为了防止出错,我也将您的条件从[SqlFunction(DataAccess = DataAccessKind.None, IsDeterministic = true, Name = "RegexReplaceStrings")] public static SqlString ReplaceStrings(SqlString sqlInput, SqlString sqlPattern, SqlString sqlReplacement, SqlString sqlSeparator) { string returnValue = ""; // if any of the input parameters is "NULL" no replacement is performed at all if (sqlInput.IsNull || sqlPattern.IsNull || sqlReplacement.IsNull || sqlSeparator.IsNull) { returnValue = sqlInput.Value; } else { string[] patterns = sqlPattern.Value.Split(new string[] {sqlSeparator.Value}, StringSplitOptions.None); string[] replacements = sqlReplacement.Value.Split(new string[] { sqlSeparator.Value }, StringSplitOptions.None); var map = new Dictionary<string, string>(); // The map structure is populated with all values from the "patterns" array as if no corresponding value exists // in the "replacements" array the current value from the "pattern" array is used a a replacement value. The // result is no replacement is done in the "sqlInput" string if the given "pattern" is matched. for (int index = 0; index < patterns.Length; index++) { map[patterns[index]] = index < replacements.Length ? replacements[index] : patterns[index]; } returnValue = Regex.Replace(sqlInput.Value, String.Join("|", patterns.Select(patern => Regex.Replace(patern, @"\(|\)|\||\.", @"\$&")).OrderByDescending(patern => patern.Length).ToArray()), match => { string currentValue; if (!map.TryGetValue(match.Value, out currentValue)) { currentValue = match.Value; } return currentValue; }); } return new SqlString(returnValue); } 更改为input$number != 0

input$number >= 1