【问题标题】:How to change the value of the function depending on what`s choosen on radio button (shinyapp)&如何根据单选按钮(闪亮的应用程序)上选择的内容更改函数的值&
【发布时间】:2017-01-11 21:18:34
【问题描述】:

如果用户选择英语,我想将函数 fuz

我尝试使用反应式表达,但它给了我一个错误:“不允许从闪亮输出对象读取对象。”

谢谢

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)

【问题讨论】:

    标签: r radio-button shiny fuzzy-logic


    【解决方案1】:

    fuz 对象仍然存在,将 output$sub 替换为 fuz 是否符合您的预期?

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

    【讨论】:

    • 感谢您的回复,但是 fuz
    • @Anastasia 抱歉,我不熟悉 sets 包。但是,错误消息表明您不能在上面的行中使用output$sub。尝试在环境中像平常一样声明您希望使用的对象,并在逻辑语句中使用它。
    • 好的,谢谢。这有效:z
    猜你喜欢
    • 2018-08-10
    • 2016-11-16
    • 2018-06-20
    • 1970-01-01
    • 2019-08-02
    • 2021-12-13
    • 1970-01-01
    • 2021-01-26
    • 1970-01-01
    相关资源
    最近更新 更多