Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R当数据有效时返回错误_R_Validation_Shiny - Fatal编程技术网

R当数据有效时返回错误

R当数据有效时返回错误,r,validation,shiny,R,Validation,Shiny,我有一个闪亮的应用程序,在没有数据的情况下会产生错误,我正在尝试使用validate生成更好的错误消息。我已经让它对没有数据的变量起作用,但是在有数据的地方,我得到了一个错误,应该出现一个图(或表) 使用下面的代码,我得到下面的错误 else if (input$geo=="Alaska, 2015") { data <- switch( validate(need(input$var != "Sexual Orientation", "Data Unavailab

我有一个闪亮的应用程序,在没有数据的情况下会产生错误,我正在尝试使用validate生成更好的错误消息。我已经让它对没有数据的变量起作用,但是在有数据的地方,我得到了一个错误,应该出现一个图(或表)

使用下面的代码,我得到下面的错误

else if (input$geo=="Alaska, 2015") {
    data <- switch(
        validate(need(input$var != "Sexual Orientation", "Data Unavailable")),
        input$var, 
        "Housing Status" = hmlweightak,
        "Sex" = sexweightak,
        "Race/Ethnicity" = raceethweightak,
        "Sexual Orientation" = "",
        "Bullied at School in the last 12 Months" = bsweightak,
        "Missed School due to Safety Concerns" = usweightak,
        "Deliberately hurt by an intimate partner" = pvweightak,
        "Forced to Perform Sexual Acts by Intimate Partner in the last 12 Months" = saweightak,
        "Binge Drank in the last 30 days" = bdweightak,
        "First Tried Alcohol by Age 12" = faweightak,
        "First Tried Marijuana by Age 12" = fmweightak,
        "Suffered from Depression in the last 12 Months" = dweightak,
        "Had Suicidal Thoughts in the last 12 Months" = stweightak,
        "Attempted Suicide in the last 12 Months" = asweightak,
        "Required Medical Attention After Suicide Attempt in the last 12 Months" = smweightak,
        "Ever Used Illegal Drugs" = sdweightak,
        "Used Prescription Drugs Without a Prescription" = pdweightak,
        "Sexually Active by Age 13" = fiweightak,
        "Drank or Used Drugs Before Last Sexual Intercourse" = ddliweightak,
        "Breakfast in the Last 7 Days" = "",
        "Average Hours of Sleep per Night" = hsweightak,
        "Used a Condom During Last Sexual Intercourse" = clweightak,
        "Asthma" = aweightak
    )
}
else if(输入$geo==“阿拉斯加,2015”){

数据问题在于
开关
验证
语句的组合

switch(input$dropDownValue,
       iris = datasets::iris,
       cars = datasets::cars)
假设根据您输入的$dropDownValue,您希望返回一个或另一个数据集。对于
iris
return datasets::iris
,您需要以下语句

switch(input$dropDownValue,
       iris = datasets::iris,
       cars = datasets::cars)
validate
如果第一条语句的evaluate为
FALSE
,则仅停止函数的执行并添加验证消息

你的情况应该是这样的

validate(need(input$var != "Sexual Orientation", "Data Unavailable"))
data <- switch(input$var, 
               "Housing Status" = hmlweightak,
               "Sex" = sexweightak,
               [...]
               )

这很好用,很简单!我不敢相信我没有试过,但非常感谢你!