firebase
firebase copied to clipboard
storage download and list files not returning responses
Hi, I tried the demo sample code in the documentation, however, no responses are returned for both methods. Am I missing something? Thank you.
Do you have everything configured correctly in your Google console? Also make sure you have the environment variables set properly, see config
Yes. Auth, upload and delete works just fine (files are uploaded and deleted). Not sure about download. I did not change any of the sample code, this here returns null:
observeEvent(s$get_response("dl"), { print(s$get_response("dl")) })
edit: I checked the client console, js script is getting response and passing the values back to Shiny, however, the above code is showing NULL.
here is the part of web socket log (I masked the url to retrieve the file).
{"method":"update","data":{"dl":{"response":"MASKED ","success":true}}}
I pushed a fix, can you install from Github and try again with the code below?
I think get_response
breaks on later shiny versions
library(shiny)
library(firebase)
ui <- fluidPage(
useFirebase(), # import dependencies
firebaseUIContainer(),
reqSignin(h4("Logged in!")), # hide from UI
uiOutput("uploadUI"),
uiOutput("downloadUI"),
uiOutput("deleteUI")
)
server <- function(input, output){
f <- FirebaseUI$
new()$ # instantiate
set_providers( # define providers
email = TRUE,
google = TRUE
)$
launch() # launch
s <- Storage$new()$
ref("logo.png")
# upload a file
output$uploadUI <- renderUI({
f$req_sign_in()
actionButton("upload", "Upload Image")
})
observeEvent(input$upload, {
s$upload_file("docs/logo.png", "up")
})
observeEvent(input$up, {
print(input$up)
})
# download a file
output$downloadUI <- renderUI({
f$req_sign_in()
actionButton("download", "Download Image")
})
observeEvent(input$download, {
s$download_file("dl")
})
observeEvent(input$dl, {
print(input$dl)
})
# delete file
output$deleteUI <- renderUI({
f$req_sign_in()
actionButton("delete", "Delete Image")
})
observeEvent(input$delete, {
s$delete_file("del")
})
observeEvent(input$del, {
print(input$del)
})
}
shinyApp(ui, server)
Thanks. Tested again. input$del works, returning the responses. get_response() method still returning null. I suppose this solves the problem.
This is very strange. Can you copy paste the code you use here to make sure we are running the same?
This is the code I run:
library(shiny)
library(firebase)
ui <- fluidPage(
useFirebase(), # import dependencies
firebaseUIContainer(),
reqSignin(h4("Logged in!")), # hide from UI
uiOutput("uploadUI"),
uiOutput("downloadUI"),
uiOutput("deleteUI")
)
server <- function(input, output){
f <- FirebaseUI$
new()$ # instantiate
set_providers( # define providers
email = TRUE,
google = TRUE
)$
launch() # launch
s <- Storage$new()$
ref("test.png")
# upload a file
output$uploadUI <- renderUI({
f$req_sign_in()
actionButton("upload", "Upload Image")
})
observeEvent(input$upload, {
s$upload_file("docs/logo.png", "up")
})
observeEvent(input$up, {
print(input$up)
})
# download a file
output$downloadUI <- renderUI({
f$req_sign_in()
actionButton("download", "Download Image")
})
observeEvent(input$download, {
s$download_file("dl")
})
observeEvent(input$dl, {
print(input$dl)
})
# delete file
output$deleteUI <- renderUI({
f$req_sign_in()
actionButton("delete", "Delete Image")
})
observeEvent(input$delete, {
s$delete_file("del")
})
observeEvent(input$del, {
print(input$del)
})
}
shinyApp(ui, server)
From the above, input$dl and input$del return responses.
I also run another script, calling get_response() method:
library(shiny)
library(firebase)
ui <- fluidPage(
useFirebase(), # import dependencies
firebaseUIContainer(),
reqSignin(h4("Logged in!")), # hide from UI
uiOutput("uploadUI"),
uiOutput("downloadUI"),
uiOutput("deleteUI")
)
server <- function(input, output, session){
f <- FirebaseUI$
new(persistence = "local")$ # instantiate
set_providers( # define providers
email = TRUE,
google = TRUE
)$
launch() # launch
s <- Storage$new()$
ref("test.png")
# upload a file
output$uploadUI <- renderUI({
f$req_sign_in()
actionButton("upload", "Upload Image")
})
observeEvent(input$upload, {
s$upload_file("DESC.txt", response = "upload")
})
observeEvent(s$get_response("upload"), {
print("observe", s$get_response("upload"))
}, ignoreNULL = FALSE)
# download a file
output$downloadUI <- renderUI({
f$req_sign_in()
actionButton("download", "Download Image")
})
observeEvent(input$download, {
s$download_file("dl")$get_response("dl")
print("download", s$get_response("dl"))
x <<- s$get_response("dl")
})
observeEvent(s$get_response("dl"), {
print(s$get_response("dl"))
x2 <<- s$get_response("dl")
})
# delete file
output$deleteUI <- renderUI({
f$req_sign_in()
actionButton("delete", "Delete Image")
})
observeEvent(input$dl, {
print(input$dl)
x <<- input$dl
})
observeEvent(input$delete, {
s$delete_file("del")
})
observeEvent(input$del, {
print(input$del)
y <<- input$del
})
observeEvent(s$get_response("del"), {
print(s$get_response("del"))
y2 <<- s$get_response("del") #keeping the response after session terminated.
})
}
shinyApp(ui, server)
The 2nd script, input$del and input$dl return the same responses as first script (as expected), but get_response() returns null.
I'm sorry, I can't reproduce this. Could you check the environment variables and make sure all is well there? Also reinstall from Github to make sure you have the latest functioning version.