【发布时间】:2017-10-31 11:57:01
【问题描述】:
我已经从我目前正在使用的代码中简化了下面的示例。我试图将用户从一组单选按钮中选择的值传递给进行的总分。我的代码工作正常,但现在我收到以下错误:
警告:as.character 中的错误:无法将“闭包”类型强制转换为“字符”类型的向量
堆栈跟踪(最内层优先): 1:运行应用程序
错误:无法将“闭包”类型强制转换为“字符”类型的向量
这听起来像是一个语法问题,但我正在尝试解决这个问题。
UI.R
ui <- fluidPage(
#title header
titlePanel("This is My Form"),
fluidRow(
column(6,
h3("BUTTON"),
radioButtons("Button1","My First Button", choices = c("Yes" = "y","No" = "n","N/a" = "na"), selected = "na", inline = T),
br(),
h3("BUTTON 2 AND 3"),
radioButtons("Button2","My Second Button", choices = c("Yes" = "y","No" = "n","N/a" = "na"), selected = "na", inline = T),
br(),
radioButtons("Button3","My Third Button",
choices = c("Yes" = "y","No" = "n","N/a" = "na"), selected = "na", inline = T),
br(),
br()
),
column(6,
h3("BUTTON 4"),
radioButtons("Button4","My Fourth Button",
choices = c("Yes" = "y","No" = "n","N/a" = "na"), selected = "na", inline = T)
)
),
actionButton(inputId = "Submit", label = "Calculate"),
(br),
mainPanel(
h1(textOutput('totals'), align = "center")
)
)
SERVER.R
server <- function(input,output,session){
button1 <- reactive({ ifelse(input$Button1 == "y", 50, ifelse(input$Button1 == "n", 25, 0)) })
button2 <- reactive({ ifelse(input$Button2 == "y", 50, ifelse(input$Button2 == "n", 25, 0)) })
button3 <- reactive({ ifelse(input$Button3 == "y", 50, ifelse(input$Button3 == "n", 25, 0)) })
button4 <- reactive({ ifelse(input$Button4 == "y", 50, ifelse(input$Button4 == "n", 25, 0)) })
output$totals <- renderText({
if (input$Submit == 0)
return(NULL)
isolate({
total <- as.numeric(Button1())+as.numeric(Button2())+as.numeric(Button3())+as.numeric(Button4())
if (is.na(total)){
print("Make Selections and Click Submit")
} else
print(total)
})
})
}
GLOBAL.R
library(shiny)
library(rsconnect)
【问题讨论】: