Comments (4)
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.
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.
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.
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:
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)
- Memoize totalResults instead of rerequesting
- Add possibility to fetch search results pages in random order
- Umlauts cannot be queried on Windows / if system locale is not UTF-8 HOT 1
- Allow users to (O-)authorize client applications on the fly via a browser window HOT 2
- Focus queries currently do not yield all results HOT 1
- In the case of timeouts, frequencies should be estimated and marked as such HOT 3
- Timed out query results are cached
- Collocation scores are incorrect if lemmatizeNodeQuery or lemmatizeCollocateQuery is TRUE
- recursiveCA demo: Error in `slice_head()`
- corpusQuery should have a context size parameter to controll snippet lengths HOT 1
- Collocation analysis is incompatible with R 4.3.0
- Bug in collocationAnalysis.R
- Add more heuristics to example search in collocationAnalysis
- Analyze syntagmatic patterns of CA results like in the CCDB
- LICENSE and LICENSE.md conflict
- textMetadata should support the new field array representation for metadata
- corpusQuery should support the new field array representation for metadata
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rkorapclient.