0

I`d like to multiply the value of function fuz <- gset_defuzzify by 2 if user choose English and by 1,5 if Spanish is chosen.

I tried to use reactive expression but it gave me an error: "Reading objects from shinyoutput object not allowed."

Thanks

P.S.: I`m still trying to get input values for "fuzzy_inference" function, maybe someone can help with that.

library(shiny) library(shinyjs) library(sets) library(datasets)

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)
Anastasia
  • 11
  • 6

1 Answers1

0

The fuz object still exists have does replacing output$sub with fuz do what you intended?

z <- reactive(if(fuz=="You schould learn German") (fuz*2))
DataJack
  • 341
  • 2
  • 13
  • Thanks for your respond, but fuz <- gset_defuzzify(fi, 'centroid'), so it will never be equal to any text. Its a number. So if English is choosen this number should be multiplied by 2. – Anastasia Jan 11 '17 at 13:38
  • @Anastasia Sorry I am not familiar with the sets package. However the error message is indicating that you cannot use `output$sub` in the above line. Try declaring the object you wish to use like normal in the environment and using that in the logical statement. – DataJack Jan 11 '17 at 13:55
  • Yes, thanks. This works: z <- reactive(if(input$RB=="English") (fuz*2)) Finally! – Anastasia Jan 11 '17 at 14:18