r - Shiny submitButton not updating my result -


i using shiny make rcode interactive. @ first run, got initial result my initial shiny output. problem have submitbutton should update result after changing input not working. have searched stackoverflow , not find solution. glad if can help.

my ui.r code is:

      library(shiny)       source("travelcbr1.r")        shinyui(fluidpage(          # application title.         titlepanel("travel recommendation"),           sidebarlayout(           sidebarpanel(             selectinput("holidaytype", "choose holiday type:",                          choices = c("bathing", "active", "education", "recreation", "wandering", "language", "skiing", "city")),              selectinput("transportation", "choose means of transportation:",                          choices = c("plane", "train", "coach", "car")),              selectinput("accomodation", "choose accomodation:",                          choices = c("one star", "two stars", "three stars", "four stars", "five stars", "holiday flat")),              selectinput("duration", "duration (days):",                          choices = c("less 4", "4 - 6", "7 - 9", "10 - 12", "13 - 15", "16 - 20", "more 20" )),              numericinput("price", "price:", 500),             # selectinput("price", "price ($):",             #             choices = c("less 500", "500 - 1000", "1000 - 1500", "1500 - 2000", "2000 - 2500", "2500 - 3000", "3500 - 4000", "4000 - 4500", "500+" )),              selectinput("season", "season:",                          choices = c("january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december")),              selectinput("numberofpersons", "number of persons:", choices = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12 , above")),              helptext("click submit button view 6 best destinations"),              submitbutton("update")           ),             mainpanel(                tableoutput("view")               # datatableoutput("view")           )         )       )) 

my server.r code this:

    library(shiny)      source("travelcbr1.r")      shinyserver(function(input, output) {          output$view <- rendertable({            accomodation <- reactive({switch(input$accomodation,                                             "holiday flat" = 6,                                            "five stars" = 5,                                            "four stars" = 4,                                            "three stars" = 3,                                            "two stars" = 2,                                            "one star" = 1)})            price <- reactive({input$price})             transportation <- reactive({switch(input$transportation,                                               "plane" = 4,                                              "train" = 3,                                              "coach" = 2,                                              "car" = 1)})            holidaytype <- reactive({switch(input$holidaytype,                                            "active" = 8,                                           "skiing" = 7,                                           "bathing" = 6,                                           "wandering" = 5,                                           "recreation" = 4,                                           "city" = 3,                                           "language"= 2,                                           "education" = 1)})            season <- reactive({switch(input$season, "december" = 1, "january" = 1, "february" = 1,                                      "march" = 2, "april" = 2, "may" = 2,                                      "june" = 3, "july" = 3, "august" = 3,                                      "september" = 4, "october" = 4, "november" = 4)})            duration <- reactive({switch(input$duration,                                         "less 4" = 1,                                        "4 - 6" = 2,                                        "7 - 9" = 3,                                        "10 - 12" = 4,                                        "13 - 15" = 5,                                        "16 - 20" = 6,                                        "more 20" = 7           )})             numberofpersons <- reactive({switch(input$numberofpersons,                                                "12" = 12,                                               "11" = 11,                                               "10" = 10,                                               "9" = 9,                                               "8" = 8,                                               "7" = 7,                                               "6" = 6,                                               "5" = 5,                                               "4" = 4,                                               "3" = 3,                                               "2" = 2,                                               "1" = 1           )})                    travelcbr(accomodation(),                    numberofpersons(),                    transportation(),                    holidaytype(),                    season(), duration(), price())         })        }) 

i try avoid submit button. here example using actionbutton. eventreactive isolate reactive connections in expression , use input$update trigger.

btw, renderxxx reactive, don't have use reactive inside renderxxx expression.

ui

library(shiny) #source("travelcbr1.r")  shinyui(fluidpage(    # application title.   titlepanel("travel recommendation"),     sidebarlayout(     sidebarpanel(       selectinput("holidaytype", "choose holiday type:",                    choices = c("bathing", "active", "education", "recreation", "wandering", "language", "skiing", "city")),        selectinput("transportation", "choose means of transportation:",                    choices = c("plane", "train", "coach", "car")),        selectinput("accomodation", "choose accomodation:",                    choices = c("one star", "two stars", "three stars", "four stars", "five stars", "holiday flat")),        selectinput("duration", "duration (days):",                    choices = c("less 4", "4 - 6", "7 - 9", "10 - 12", "13 - 15", "16 - 20", "more 20" )),        numericinput("price", "price:", 500),       # selectinput("price", "price ($):",       #             choices = c("less 500", "500 - 1000", "1000 - 1500", "1500 - 2000", "2000 - 2500", "2500 - 3000", "3500 - 4000", "4000 - 4500", "500+" )),        selectinput("season", "season:",                    choices = c("january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december")),        selectinput("numberofpersons", "number of persons:", choices = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12 , above")),        helptext("click submit button view 6 best destinations"),        actionbutton("update", "update")     ),       mainpanel(       verbatimtextoutput("view")       # datatableoutput("view")     )   ) )) 

server

library(shiny)  #source("travelcbr1.r")  shinyserver(function(input, output) {    view <- eventreactive(input$update, {      accomodation <- switch(input$accomodation,                                       "holiday flat" = 6,                                      "five stars" = 5,                                      "four stars" = 4,                                      "three stars" = 3,                                      "two stars" = 2,                                      "one star" = 1)      price <- input$price       transportation <- switch(input$transportation,                                         "plane" = 4,                                        "train" = 3,                                        "coach" = 2,                                        "car" = 1)      holidaytype <- switch(input$holidaytype,                                      "active" = 8,                                     "skiing" = 7,                                     "bathing" = 6,                                     "wandering" = 5,                                     "recreation" = 4,                                     "city" = 3,                                     "language"= 2,                                     "education" = 1)      season <- switch(input$season, "december" = 1, "january" = 1, "february" = 1,                                "march" = 2, "april" = 2, "may" = 2,                                "june" = 3, "july" = 3, "august" = 3,                                "september" = 4, "october" = 4, "november" = 4)      duration <- switch(input$duration,                                   "less 4" = 1,                                  "4 - 6" = 2,                                  "7 - 9" = 3,                                  "10 - 12" = 4,                                  "13 - 15" = 5,                                  "16 - 20" = 6,                                  "more 20" = 7)      numberofpersons <- switch(input$numberofpersons,                                          "12" = 12,                                         "11" = 11,                                         "10" = 10,                                         "9" = 9,                                         "8" = 8,                                         "7" = 7,                                         "6" = 6,                                         "5" = 5,                                         "4" = 4,                                         "3" = 3,                                         "2" = 2,                                         "1" = 1)      list(accomodation = accomodation,        numberofpersons = numberofpersons,        transportation = transportation,        holidaytype = holidaytype,        season = season, duration = duration, price = price)      }, ignorenull = false)    output$view <- renderprint(view())  }) 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -