Yaacov Petscher Yaacov Petscher - 2 months ago 11
R Question

Shiny App creation - Passing result to table; reading objects from Shiny not allowed

I am relatively new to the shiny app and trying to create some basic decision rules that will output a classification scheme based on the defined rules. My platform and R version are:

platform: x86_64_w64_mingw32
R version: 3.2.1 (2015_06_18)

I receive an error of: Error in $.shinyoutput: Reading objects from shinyoutput object not allowed when attempting to test the output of #Profile 1 where Fall LNF scores are < 20.5 (i.e., input$fluency2<20.5 using the renderPrint for the object "a"). For the multiple if statements I have print commands that print to the R console but cannot figure out how to have the information post to the mainPanel "Groupings" defined in the ui object. Below is my script for the ui, server, and ShinyApp commands. Any help is greatly appreciated.

ui<-(fluidPage(titlePanel("testapp"),
sliderInput(inputId="fluency1", label="Fall FSF",value=25,min=0,max=200),
sliderInput(inputId="fluency2", label="Fall LNF",value=25,min=0,max=200),
mainPanel(h5("Groupings"),
textOutput("stuff"))))


server<-function(input,output) {observe({
#PROFILE 1
if ( (input$fluency2<20.5)) {
#print("Profile 1")
a<-renderPrint(output$stuff({"Profile 1"}))
a()
}
if( (input$fluency1<12) & ((input$fluency2>20)) & (input$fluency2<23)) {
print("Profile 1")
}
if( (input$fluency1<9) & ((input$fluency2>21)) & (input$fluency2<25)) {
print("Profile 1")
}

#PROFILE 2
if ( (input$fluency1>11)) {
print("Profile 2")
}
if( ((input$fluency1>8) & (input$fluency1<28)) & ((input$fluency2>22) & (input$fluency2<25))) {
print("Profile 2")
}
if( (input$fluency1<28) & ((input$fluency2>24))) {
print("Profile 2")
}

#PROFILE 3
if( (input$fluency1>27) & ((input$fluency2>23))) {
print("Profile 3")
}})}


shinyApp(server=server,ui=ui)

Answer

Does this help?

ui<-(fluidPage(titlePanel("testapp"),
                   sliderInput(inputId="fluency1", label="Fall FSF",value=25,min=0,max=200),
                   sliderInput(inputId="fluency2", label="Fall LNF",value=25,min=0,max=200),
                   mainPanel(h5("Groupings"),
                             textOutput("stuff"))))


    server<-function(input,output) {

            profile <- reactive({
                    if ( (input$fluency2<20.5)) {
                            tmp <- "Profile 1"
                    } 
                    if( (input$fluency1<12) & ((input$fluency2>20)) & (input$fluency2<23)) {
                            tmp <- "Profile 1"
                    } 
                    if( (input$fluency1<9) & ((input$fluency2>21)) & (input$fluency2<25)) {
                            tmp <- "Profile 1"
                    } 

                    #PROFILE 2
                    if ( (input$fluency1>11)) {
                            tmp <- "Profile 2"
                    } 
                    if( ((input$fluency1>8) & (input$fluency1<28)) & ((input$fluency2>22) & (input$fluency2<25))) {
                            tmp <- "Profile 2"
                    } 
                    if( (input$fluency1<28) & ((input$fluency2>24))) {
                            tmp <- "Profile 2"
                    } 

                    #PROFILE 3
                    if( (input$fluency1>27) & ((input$fluency2>23))) {
                            tmp <- "Profile 3"
                    }
                    tmp

            })
            output$stuff <- renderText({
                    profile()
            })
    }


    shinyApp(server=server,ui=ui)
Comments