Vector output indexed cycle with mixing each round

shiny

#1

Hello,

currently I'm working on a language practice application for japanese alphabet hiragana. The functional part is simple. With a press of the button_1 it produces the hiragana symbol as a output. When the button_2 is pressed it produces the reading of the symbol. Every symbol displayed and its value is displayed randomly so now I cannot achieve output without repetition.

My goal now is to make the application more practical without any repetition. To achieve this I got an idea that the app should work like this:

  1. Mix the elements of the vector "data"
  2. For each element(going from the first one to the last of the mix) output name of the element with the press of the button_1
  3. Then with the press of the button_2 output the value of the element.
  4. If there are no more elements to work with then mix the vector "data" again and do the same procedure presented in steps 2. and 3.

My current thoughts are that for each of those iterations I should save the sample(data) to a new vector and then apply some if conditions. Unfortunately the way I did it it still sometimes repeat the displayed element name and doesn't work without repetition. I will highly appreciate any feedback and tips. Thank you very much in advance.

data <- c("あ" = "a", "え" = "e", "い" = "i", "お" = "o", "う" = "u", "か" = "ka", "け" ="ke", "き" = "ki", "こ" = "ko", "く" = "ku")


library(shiny)

shinyServer((function(input, output) {
  values <- reactiveValues(one = 0, two = 0)
  
  symbol_final <- ""
  symbol_meta <- ""
  mixed_data <- ""
  index <- 1
  
  
  observeEvent(input$button_1, {
    values$one <- 1
    values$two <- 0
    
  })
  
  observeEvent(input$button_2, {
    values$one <- 0
    values$two <- 1
    
  })
  
  
  
  output$Output_1 <- renderText(
    {
      
      
      mixed_data <<- sample(data)
 
    
      
      if(values$one) {
      
        if(index <= length(data)){
          symbol_final <<- names(mixed_data[index])
          mixed_data <<- sample(data)
           return(symbol_final)
          index <<- index+1
        }
        
        else{
          index <<- 1 
          mixed_data <<- sample(sample(data))
        }
        
        
        return(symbol_final)
        
      }
      else if(values$two)
      
        return(data[symbol_final])
    
    }

  )
  
  
}))