2017-01-11 4 views
0

사용자가 영어를 선택하면 function fuz < - gset_defuzzify의 값을 2로, if를 선택하면 if 스페인어가 선택됩니다.라디오 버튼 (shinyapp)에서 무엇을 선택 했느냐에 따라 함수의 값을 변경하는 방법 &

반응 형 표현을 사용하려고했지만 "shinyoutput 객체에서 객체를 읽을 수 없습니다."라는 오류가 발생했습니다.

감사

P.S : 나는`여전히 "fuzzy_inference"기능에 대한 입력 값을 얻을려고, 어쩌면 누군가가 도움이 될 수 있습니다.

라이브러리 (반짝) 라이브러리 (shinyjs) 라이브러리 (세트) 라이브러리 (데이터 세트)

ui <- fluidPage(numericInput(inputId = "one", label="Type number",1, min=1, max=120), 
numericInput(inputId = "two", label="Type number",1, min = 1, max=120), 
     numericInput(inputId = "three", label="Type number",1, min = 1, max=120), 
     numericInput(inputId = "four", label="Type number",1, min = 1, max=120), 
     textOutput("sub"), br(), 
     actionButton("act", "Show"), 

     br(), 

     radioButtons(inputId = "RB",label="Choose", 
        c("English", 
         "French", 
         "German", 
         "Spanish", 
         "None")), 
     textOutput("sw"), 
     textOutput("text") 


) 
server <- function(input, output){ 
output$text <- renderText({ 
RB <- switch(input$RB, 
     English= "You schould learn German.", 
     French = "You schould learn Spanish.", 
     German = "You schould learn English.", 
     Spanish = "You schould learn Portuguese.", 
     None ="You schould learn Polish.") 
}) 
variables <- set(wo = fuzzy_partition(varnames = c(notMany2 = 15, enough2 = 25, many2 = 35),FUN = fuzzy_cone, radius = 10), 
      top = fuzzy_partition(varnames = c(notMany3 = 20, enough3 = 50, many3 = 100),FUN = fuzzy_cone, radius = 25), 
      c = fuzzy_partition(varnames = c(k4 = 52, k3 = 42, k2 = 32,k1 = 22), sd = 3) 
) 
rules <- set (fuzzy_rule(wo %is% notMany2 && top %is% notMany3 
        || wo %is% notMany2 && top %is% notMany3 
        || wo %is% notMany2 && top %is% notMany3 
        , c %is% k1), 
     fuzzy_rule(wo %is% notMany2 && top %is% enough3 
        || wo %is% notMany2 && top %is% many3,c %is% k2)) 
system <- fuzzy_system(variables,rules) 

fi <- fuzzy_inference(system, list(wo = 20, top= 10)) 

    fuz <- gset_defuzzify(fi, 'centroid') 

output$sub <- renderText({fuz}) 
z <- reactive(if(output$sub=="You schould learn German") (fuz*2)) 
output$sw <- renderText({z()}) 


} 


shinyApp(ui = ui, server = server) 

답변

0

는 fuz 객체는 여전히이 존재 fuzoutput$sub를 교체하면 의도 않는 무엇?

z <- reactive(if(fuz=="You schould learn German") (fuz*2)) 
+0

답장을 보내 주셔서 감사합니다.하지만 fuz <- gset_defuzzify (fi, 'centroid')이므로 어떤 텍스트와도 동일하지 않습니다. 그것의 번호. 영어가 선택되면이 숫자에 2를 곱해야합니다. – Anastasia

+0

@Anastasia 죄송합니다. 세트 패키지에 익숙하지 않습니다. 그러나 오류 메시지는 위의 행에서'output $ sub'을 사용할 수 없다는 것을 나타냅니다. 환경에서 정상적으로 사용하려는 객체를 선언하고 논리 구문에서이를 사용하십시오. – DataJack

+0

네, 고마워요. 이것은 작동합니다 : z <- reactive (if (input $ RB == "English") (fuz * 2)) 마침내! – Anastasia