我是闪亮的新手,很难弄清楚这一点。我试图在 selectizeInput 中创建一个“全选”按钮,但在将输入从 selectizeInput 传递到 updateSelectizeInput 时遇到错误。有人可以帮我解决这个问题吗?
当我从输入框中选择“全选”时,应用程序关闭并显示错误:“$ 运算符对于原子向量无效”
我在输入字段(selectizeInput())中添加了“全选”。当用户单击“全选”时,updateSelectizeInput() 将添加输入中的所有名称与“全选”之间的设置差异,并用所有值填充过滤器框。
脚本的数据:https://drive.google.com/file/d/0B_sB3ef_9RntOWJjNlhrUjk3a1k/view https://drive.google.com/file/d/0B_sB3ef_9RntOWJjNlhrUjk3a1k/view
这是我的脚本
UI.R
library(shiny)
shinyUI(fluidPage(
navbarPage(
"Tab_name",
tabPanel("Engine",
bootstrapPage(
div(style="display:inline-block", fileInput("file_attr", "attributes:")),
uiOutput("CountryList")
)
)
)
))
Server.R
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)
}
})
})
当我们从 UI 的输入字段中选择“全选”时,会出现错误
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
Thanks!