0
我簡化了我的示例,下面是我正在使用的代碼。我試圖將用戶從一組單選按鈕中選擇的值傳遞給總分。我的代碼工作正常,但現在我收到以下錯誤:嘗試將單選按鈕值傳遞給服務器時出現類錯誤
Warning: Error in as.character: cannot coerce type 'closure' to vector of type 'character'
Stack trace (innermost first): 1: runApp
Error : cannot coerce type 'closure' to vector of type 'character'
這聽起來像這是一個語法問題,但我畫一個空白試圖弄清楚這一點。
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)
再就是像'Button1的其他問題()'而不是'按鈕1()'但這地址問題的特定錯誤消息。 – MrFlick