2017-02-13 16 views
0

У меня вопрос о блестящем приложении. Когда нет значения, выбранного в числовом входе и selectizeInput, мое блестящее приложение покажет ошибку из-за пустого кадра данных. Я хотел бы скрыть сообщение об ошибке, если пользователь еще не выбрал свой ввод. Я знаю, что ifreturn поможет, но он не работает в этом приложении.Shiny/R: Скрыть сообщение об ошибке, когда нет значения в selectizeInput

server.r:

library(shiny) 

# Define server logic required to draw a histogram 
shinyServer(function(input, output) { 

result<-reactive({ 
    if(is.null(input$wt)||is.null(input$hdcount)||is.null(input$season)||is.null(inp ut$gender))return(NULL) 

mod1<-lm(deathLog ~ InHdCnt+ log(InHdCnt) + season+ SexCode+ AvgArrivWt, data=mydata) 
newdata = data.frame(AvgArrivWt=input$wt,InHdCnt=input$hdcount,SexCode=input$gender,season=input$season) 
data<-predict(mod1, newdata, interval="predict",level=(input$slider1)*0.01) 
data 

}) 

output$distPlot <- renderPrint({ 

result() 
}) 

}) 

ui.r:

library(shiny) 

# Define UI for application that draws a histogram 
shinyUI(fluidPage(

# Application title 
titlePanel("Death Loss Estimator with On Arrival Factors"), 

# Sidebar with a slider input for number of bins 
sidebarLayout(
sidebarPanel(
    numericInput("wt", label = h4("Average Arrival Weight input"),value="NULL"), 
    numericInput("hdcount", label = h4("Arrival Head Count input"),value="NULL"), 
    selectizeInput(
    'season', h4('Arrival Season'), choices = c("spring", "summer","fall", "winter"), 
    options = list(
     placeholder = 'Please select a season below', 
     onInitialize = I('function() { this.setValue(""); }') 
    ) 
    ), 
    selectizeInput(
    'gender', h4('Arrival Sex'), choices = c("HOL", "FEM","MAL", "MIX"), 
    options = list(
     placeholder = 'Please select a season below', 
     onInitialize = I('function() { this.setValue(""); }') 
    ) 
    ), 
    sliderInput("slider1", label = h4("Confidence Interval Level"), min = 50, 
       max = 100, value = 80) 
    ), 

    # Show a plot of the generated distribution 
    mainPanel(
    textOutput("distPlot") 
) 
) 
)) 

Спасибо!

+1

'данных = mydata' не помогает. не могли бы вы отредактировать сообщение и сделать код воспроизводимым –

+2

'if (is.null (input $) | is.null (input $) | ...) {return()}' – Akbar

+1

'' req' может помочь. –

ответ

4

Я бы рекомендовал использовать проверку и необходимость. Вы можете поместить это в верхней части реакционно выражения:

validate(
    need(input$wt, "Please select a weight"), 
    need(input$hdcount, "Please select a head count") 
) 

В качестве альтернативы вы можете использовать Req:

req(input$wt) 
req(input$hdcount) 
+0

Большое вам спасибо! Это работает! – Joanna

 Смежные вопросы

  • Нет связанных вопросов^_^