0

Firstly, I found another topic about that error on StackOverflow, but it didn't helped me.

Im trying to tell Shiny when an user logs in (or out) on my website, but I got the following error:

lwd.js:8 Uncaught (in promise) TypeError: Shiny.onInputChange is not a function at LoginWithDiscord._onlogin (lwd.js:8) at LoginWithDiscord.init (lwd.js:39) at (index):24

I really can't understand why, since I AM USING SHINY. I tried the same method on my job's machine and it works very well.

There is some of my code, if you want more just ask :)

this._onlogin = () => {
      let user = discord.fetchUser();
      Shiny.onInputChange('discordupfp', user.avatarURL);
      Shiny.onInputChange('discorduid', user.id);
      Shiny.onInputChange('discordusername', user.username);
    };
    this._onlogout = () => { 
      Shiny.onInputChange('discord-logout', 1);
    };

server.r:

 discordpfp = NULL
  discorduid = NULL
  discordusername = NULL
  lang = "us"


  observeEvent(input$discordpfp, {
    userpfp = input$discordpfp
  })

  observeEvent(input$discoruid, {
    discorduid = input$discorduid
  })

  observeEvent(input$discordusername, {
    userpfp = input$discordusername
  })

  discordarea = reactive({
    if(is.null(discorduid)){
      #No problem on showing my id
      tags$button(onClick="discord.login('342488102318637059', Scope.Identify)", class="login-button", "LOGIN")
    } else {
      tags$img(
        src=discordpfp,
        class="discord-image",
        width="75"
      )
      div(id="poupup-element",
          div(class="discord-poupup",
              tags$button(onClick="discord.logout()", class="logout-button", "LOGOUT")
          )
      )
    }
  })

  output$discordarea = renderUI({
    return(discordarea())
  })

  observeEvent(input$discordlogout, {
    discordpfp = NULL
    discorduid = NULL
    discordusername = NULL
    lang = "us"
  })
NathanPB
  • 685
  • 1
  • 7
  • 22
  • It's just a blind guess, but in recent Shiny version (1.1) `Shiny.onInputChange` was changed to `Shiny.setInputValue`. However, in the docs you can read that `Shiny.onInputChange` is still supported (https://shiny.rstudio.com/articles/communicating-with-js.html). But who knows? Aren't you using different Shiny versions on your personal and job machines? – Mikolaj Jun 07 '18 at 14:57
  • Yes, I am. On my job machine I'm using R 3.3.1. On my personal one Im using R 3.5.1 (I don't remember exactly), but the same Shiny version. I'll check it when I get home – NathanPB Jun 07 '18 at 17:43

0 Answers0