闪亮:updateSelectizeInput引发错误“ $运算符对于原子向量无效”

纳雷什·安巴蒂

我是新来的有光泽的人,很难解决这个问题。我试图在我的selectizeInput中创建一个“全选”按钮,但是在将输入从selectizeInput传递到updateSelectizeInput时遇到错误。有人可以帮我解决这个问题。

当我从输入框中选择“全选”时,应用程序关闭并显示错误:“ $运算符对原子向量无效”

我在输入字段(selectizeInput())中添加了“全选”。当用户单击“全选”时,updateSelectizeInput()在输入中的所有名称和“全选”之间添加设置差异,并用所有值填充过滤器框。

脚本的数据:https : //drive.google.com/file/d/0B_sB3ef_9RntOWJjNlhrUjk3a1k/view

这是我的剧本

用户界面

library(shiny)
shinyUI(fluidPage(
  navbarPage(
    "Tab_name",
    tabPanel("Engine",
             bootstrapPage(
               div(style="display:inline-block", fileInput("file_attr", "attributes:")),
               uiOutput("CountryList")
             )         
    )
  )
))

服务器

library(shiny)
shinyServer(function(input, output) {     
  data_attr <- reactive({
      file1 <- input$file_attr
      if(is.null(file1)){return()} 
      read.table(file=file1$datapath, sep=",", header = TRUE, stringsAsFactors = FALSE)       
    })

    countries <- reactive({
      if(is.null(data_attr()$Country)){return()}
      data_attr()$Country
    })  

    observeEvent(input$file_attr, {
      output$CountryList <- renderUI({
        if(is.null(data_attr()$Country)){return()}
        selectizeInput('show_vars', 'Country Filter', choices = c("Select All",unique(countries())), multiple = TRUE)
      })
    }) 

    observe({
      if ("Select All" %in% input$show_vars){
        selected_choices <- setdiff(c("Select All",unique(countries())), "Select All")
        updateSelectizeInput('show_vars', 'Country Filter', selected = selected_choices)

      }

    })

  })

当我们从用户界面的输入字段中选择“全选”时,就会出现错误

Warning: Error in $: $ operator is invalid for atomic vectors
Stack trace (innermost first):
    58: updateSelectInput
    57: updateSelectizeInput
    56: observerFunc [C:\Users\naresh.ambati\Documents\dummt/server.R#30]
     1: runApp
ERROR: [on_request_read] connection reset by peer

谢谢!

SBista

该错误是因为您传递给更新的参数updateSelectizeInput不正确。您需要将session对象作为第一个参数传递在您的情况下,应该是这样的:

updateSelectizeInput(session,'show_vars', 'Country Filter', selected = selected_choices)

在定义服务器功能时,您需要session按以下方式传递对象:

shinyServer(function(input, output, session) { 

.......

} 

希望能帮助到你!

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

插入符:: train函数中的“错误:$运算符对于原子向量无效”

错误:$ 运算符对原子向量无效(r 闪亮 ggplot)

随机森林模型的Rcaret提取预测:错误:$运算符对于原子向量无效

ggplot2错误:$运算符对于原子向量无效

Apply函数返回“错误:$运算符对于原子向量无效”

$ 运算符对闪亮的 R 中的原子向量无效

plot.lm错误:$运算符对原子向量无效

rfe() 函数错误:$ 运算符对原子向量无效

model.matrix错误:$运算符对原子向量无效

方差分析:错误:$运算符对原子向量无效

错误$运算符对制作直方图R的原子向量无效

biglm - 错误:$ 运算符对原子向量无效

尽管未使用原子向量或 $,但错误“$ 运算符对原子向量无效”

将函数应用于不同的数据子集时,对于3个子集中的1个,会出现“错误:$运算符对于原子向量无效”

x $ j中的错误:$运算符对文本聚类中的原子向量无效

第一个函数中的错误:$运算符对原子向量无效

模糊匹配:避免出现“错误:$运算符对原子向量无效”

caret::predict 给出错误:$ 运算符对原子向量无效

HR.Rates $ y中的错误:$运算符对原子向量无效

使用 ggsave 时遇到“错误:$ 运算符对原子向量无效”

两个函数-一个很好,一个有错误:$运算符对原子向量无效

运算符对于函数内部的原子向量无效

Speeglm $运算符对原子向量无效

如何从RxJS映射运算符引发错误(角度)

UglifyJS引发错误意外令牌:运算符(>)

一元运算符的无效参数-错误消息-负dplyr ::用向量选择

R fromJSON - $ 运算符对原子向量无效

SQL Server中的R:$运算符对原子向量无效

==运算符的“无效分配”错误