Git Product home page Git Product logo

Comments (4)

daniel-jach avatar daniel-jach commented on July 22, 2024 1

That worked, both locally and on shinyapps.io.

For anyone who struggles to grasph the underlying logic (like I do), here is my updated code:

library(shiny)
library(RKorAPClient)

# UI
ui <- fluidPage(
  titlePanel("Login Shiny App Template"),
  mainPanel(
    textInput("accessToken", "Please enter your access token here."),
    actionButton("loginButton", "Enter."),
    textOutput("authStatus"),
    textInput("userQuery", "Please enter a search word."),
    actionButton("queryGo", "Search."),
    tableOutput("queryResults")
  )
)

# Server
server <- function(input, output, session) {
  # Reactive value to store authentication status
  authenticated <- reactiveVal(FALSE)
  rv <- reactiveValues(kco = NULL)
  # login event
  observeEvent(input$loginButton, {
    # use user token to open connection
    rv$kco <- new("KorAPConnection", accessToken = input$accessToken)
    
    # Check if connection is successful
    if (!is.null(reactive(rv$kco))) {
      authenticated(TRUE)
      output$authStatus <- renderText("Authentication Successful!")
    } else {
      output$authStatus <- renderText("Authentication Failed.")
    }
  })
  
  # query event
  observeEvent(input$queryGo, {
    output$queryResults <- renderTable(corpusQuery(rv$kco, input$userQuery, context = '3', metadataOnly = FALSE) %>% 
                                         fetchNext() %>%
                                         slot('collectedMatches'))
  })
}

# Run the app
shinyApp(ui, server)

The kco connection is stored as a reactive value and defined globally as rv$kco. The login function updates the rv$kco value. The corpus query uses the connection with rv$kco.

End users then need to 1. log into KorAP, 2. go to the OAuth settings, 3. register a new client application (any fake name application will do), and 4. generate a token. This token can then be used as access token as described by @kupietz .

I lost a lot of days over this. Thank you very much.

from rkorapclient.

kupietz avatar kupietz commented on July 22, 2024

Thanks for the report!

It seems, unfortunately, that we cannot solve the issue at the moment as it is beyond our control between httr(2) and shinyapps. However, as we are not the only ones who have the problem, there will hopefully be a solution soon.

See r-lib/httr2#47 and r-lib/httr2#422 (comment)

For now, you either need to have the KorAP API key either specified statically in your script or you need to get it from the user via a form or parameter.

from rkorapclient.

daniel-jach avatar daniel-jach commented on July 22, 2024

Thank you for your reply. Could you please be more specific about the work around you proposed: getting the necessary input from the user via a form or parameter. What exactly would the users need to provide? Where would I feed it into the process?

In my understanding, the KorAP API key is already specified statically (in the above example, key = "hdnFfFmd4t9bhNnRfndGfH" in oauth_app()).

Thank you for your effort.

from rkorapclient.

kupietz avatar kupietz commented on July 22, 2024

Thank you for your reply. Could you please be more specific about the work around you proposed: getting the necessary input from the user via a form or parameter. What exactly would the users need to provide? Where would I feed it into the process?

In my understanding, the KorAP API key is already specified statically (in the above example, key = "hdnFfFmd4t9bhNnRfndGfH" in oauth_app()).

Sorry, I should have written access token instead of API key and it's a bit confusing, also because different points of view and terminologies mix here. From KorAP's point of view, "hdnFfFmd4t9bhNnRfndGfH" is the client application ID. The access token you can copy from KorAP's OAuth settings, in the right bottom corner here:

grafik

If you are the end user, or you want to allow the end users to make their queries on behalf of you, you can copy the token and use it staticaly like this:

kco <- new("KorAPConnection", accessToken="mJTPGnt6mhtP9dM6PFTMFx") # just an example token
collocationAnalysis(kco, "Test")

If the end users should be responsible themselves, you should be able to request a user's token via an HTML form and shiny.

from rkorapclient.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.