combine two selectbox values in r shiny












0















I need to combine two select box values in R shiny.
Select box 1 have year, select box 2 have month.



If user select 2018 and 06, I should get 2018-06 into a variable.



I tried paste(input$year,input$month,sep="-") But it is not working.










share|improve this question



























    0















    I need to combine two select box values in R shiny.
    Select box 1 have year, select box 2 have month.



    If user select 2018 and 06, I should get 2018-06 into a variable.



    I tried paste(input$year,input$month,sep="-") But it is not working.










    share|improve this question

























      0












      0








      0


      0






      I need to combine two select box values in R shiny.
      Select box 1 have year, select box 2 have month.



      If user select 2018 and 06, I should get 2018-06 into a variable.



      I tried paste(input$year,input$month,sep="-") But it is not working.










      share|improve this question














      I need to combine two select box values in R shiny.
      Select box 1 have year, select box 2 have month.



      If user select 2018 and 06, I should get 2018-06 into a variable.



      I tried paste(input$year,input$month,sep="-") But it is not working.







      r select shiny concatenation selectinput






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 26 '18 at 8:45









      qwwwqwww

      427211




      427211
























          1 Answer
          1






          active

          oldest

          votes


















          3














          This should do, note that I changed from reative to reactiveValues as I think this should be more intutive for you where you can use the v$value which will contain what you want. I suggest you have a read over https://shiny.rstudio.com/articles/reactivity-overview.html so you have a better grasp of what is happening



          library(shiny)

          ui <- fluidPage(
          textOutput("value"),
          selectInput("year","year",choices = c(2017,2018),selected = 1),
          selectInput("month","month",choices = c(1:12),selected = 1)

          )

          server <- function( session,input, output) {

          v <- reactiveValues(value=NULL)

          observe({
          year <- input$year
          month <- input$month
          if(nchar(month)==1){
          month <- paste0("0",month)
          }
          v$value <- paste(year,month,sep="-")
          })

          output$value <- renderText({
          v$value
          })
          }

          shinyApp(ui, server)





          share|improve this answer


























          • How to get this value into some variable?

            – qwww
            Nov 26 '18 at 9:10











          • that value is in the variable called Combined()

            – Pork Chop
            Nov 26 '18 at 9:22











          • Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)

            – qwww
            Nov 26 '18 at 9:24






          • 1





            If you have a look at the ?reactive you can see that its an expression and not to be used as a value, instead you can either use reactiveVal or reactivevalues

            – Pork Chop
            Nov 26 '18 at 9:50













          • I am still getting the same error and my shiny app is closing

            – qwww
            Nov 26 '18 at 9:58











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53477400%2fcombine-two-selectbox-values-in-r-shiny%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          This should do, note that I changed from reative to reactiveValues as I think this should be more intutive for you where you can use the v$value which will contain what you want. I suggest you have a read over https://shiny.rstudio.com/articles/reactivity-overview.html so you have a better grasp of what is happening



          library(shiny)

          ui <- fluidPage(
          textOutput("value"),
          selectInput("year","year",choices = c(2017,2018),selected = 1),
          selectInput("month","month",choices = c(1:12),selected = 1)

          )

          server <- function( session,input, output) {

          v <- reactiveValues(value=NULL)

          observe({
          year <- input$year
          month <- input$month
          if(nchar(month)==1){
          month <- paste0("0",month)
          }
          v$value <- paste(year,month,sep="-")
          })

          output$value <- renderText({
          v$value
          })
          }

          shinyApp(ui, server)





          share|improve this answer


























          • How to get this value into some variable?

            – qwww
            Nov 26 '18 at 9:10











          • that value is in the variable called Combined()

            – Pork Chop
            Nov 26 '18 at 9:22











          • Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)

            – qwww
            Nov 26 '18 at 9:24






          • 1





            If you have a look at the ?reactive you can see that its an expression and not to be used as a value, instead you can either use reactiveVal or reactivevalues

            – Pork Chop
            Nov 26 '18 at 9:50













          • I am still getting the same error and my shiny app is closing

            – qwww
            Nov 26 '18 at 9:58
















          3














          This should do, note that I changed from reative to reactiveValues as I think this should be more intutive for you where you can use the v$value which will contain what you want. I suggest you have a read over https://shiny.rstudio.com/articles/reactivity-overview.html so you have a better grasp of what is happening



          library(shiny)

          ui <- fluidPage(
          textOutput("value"),
          selectInput("year","year",choices = c(2017,2018),selected = 1),
          selectInput("month","month",choices = c(1:12),selected = 1)

          )

          server <- function( session,input, output) {

          v <- reactiveValues(value=NULL)

          observe({
          year <- input$year
          month <- input$month
          if(nchar(month)==1){
          month <- paste0("0",month)
          }
          v$value <- paste(year,month,sep="-")
          })

          output$value <- renderText({
          v$value
          })
          }

          shinyApp(ui, server)





          share|improve this answer


























          • How to get this value into some variable?

            – qwww
            Nov 26 '18 at 9:10











          • that value is in the variable called Combined()

            – Pork Chop
            Nov 26 '18 at 9:22











          • Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)

            – qwww
            Nov 26 '18 at 9:24






          • 1





            If you have a look at the ?reactive you can see that its an expression and not to be used as a value, instead you can either use reactiveVal or reactivevalues

            – Pork Chop
            Nov 26 '18 at 9:50













          • I am still getting the same error and my shiny app is closing

            – qwww
            Nov 26 '18 at 9:58














          3












          3








          3







          This should do, note that I changed from reative to reactiveValues as I think this should be more intutive for you where you can use the v$value which will contain what you want. I suggest you have a read over https://shiny.rstudio.com/articles/reactivity-overview.html so you have a better grasp of what is happening



          library(shiny)

          ui <- fluidPage(
          textOutput("value"),
          selectInput("year","year",choices = c(2017,2018),selected = 1),
          selectInput("month","month",choices = c(1:12),selected = 1)

          )

          server <- function( session,input, output) {

          v <- reactiveValues(value=NULL)

          observe({
          year <- input$year
          month <- input$month
          if(nchar(month)==1){
          month <- paste0("0",month)
          }
          v$value <- paste(year,month,sep="-")
          })

          output$value <- renderText({
          v$value
          })
          }

          shinyApp(ui, server)





          share|improve this answer















          This should do, note that I changed from reative to reactiveValues as I think this should be more intutive for you where you can use the v$value which will contain what you want. I suggest you have a read over https://shiny.rstudio.com/articles/reactivity-overview.html so you have a better grasp of what is happening



          library(shiny)

          ui <- fluidPage(
          textOutput("value"),
          selectInput("year","year",choices = c(2017,2018),selected = 1),
          selectInput("month","month",choices = c(1:12),selected = 1)

          )

          server <- function( session,input, output) {

          v <- reactiveValues(value=NULL)

          observe({
          year <- input$year
          month <- input$month
          if(nchar(month)==1){
          month <- paste0("0",month)
          }
          v$value <- paste(year,month,sep="-")
          })

          output$value <- renderText({
          v$value
          })
          }

          shinyApp(ui, server)






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 26 '18 at 9:50

























          answered Nov 26 '18 at 8:53









          Pork ChopPork Chop

          15k22545




          15k22545













          • How to get this value into some variable?

            – qwww
            Nov 26 '18 at 9:10











          • that value is in the variable called Combined()

            – Pork Chop
            Nov 26 '18 at 9:22











          • Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)

            – qwww
            Nov 26 '18 at 9:24






          • 1





            If you have a look at the ?reactive you can see that its an expression and not to be used as a value, instead you can either use reactiveVal or reactivevalues

            – Pork Chop
            Nov 26 '18 at 9:50













          • I am still getting the same error and my shiny app is closing

            – qwww
            Nov 26 '18 at 9:58



















          • How to get this value into some variable?

            – qwww
            Nov 26 '18 at 9:10











          • that value is in the variable called Combined()

            – Pork Chop
            Nov 26 '18 at 9:22











          • Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)

            – qwww
            Nov 26 '18 at 9:24






          • 1





            If you have a look at the ?reactive you can see that its an expression and not to be used as a value, instead you can either use reactiveVal or reactivevalues

            – Pork Chop
            Nov 26 '18 at 9:50













          • I am still getting the same error and my shiny app is closing

            – qwww
            Nov 26 '18 at 9:58

















          How to get this value into some variable?

          – qwww
          Nov 26 '18 at 9:10





          How to get this value into some variable?

          – qwww
          Nov 26 '18 at 9:10













          that value is in the variable called Combined()

          – Pork Chop
          Nov 26 '18 at 9:22





          that value is in the variable called Combined()

          – Pork Chop
          Nov 26 '18 at 9:22













          Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)

          – qwww
          Nov 26 '18 at 9:24





          Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)

          – qwww
          Nov 26 '18 at 9:24




          1




          1





          If you have a look at the ?reactive you can see that its an expression and not to be used as a value, instead you can either use reactiveVal or reactivevalues

          – Pork Chop
          Nov 26 '18 at 9:50







          If you have a look at the ?reactive you can see that its an expression and not to be used as a value, instead you can either use reactiveVal or reactivevalues

          – Pork Chop
          Nov 26 '18 at 9:50















          I am still getting the same error and my shiny app is closing

          – qwww
          Nov 26 '18 at 9:58





          I am still getting the same error and my shiny app is closing

          – qwww
          Nov 26 '18 at 9:58




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53477400%2fcombine-two-selectbox-values-in-r-shiny%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Costa Masnaga

          Fotorealismo

          Sidney Franklin