Reputation: 61
I am trying to make a very simple shiny app that allows the user to choose an image file from a dropdown menu and then the chosen one will be loaded from Dropbox and displayed in the shiny app. I am using the drop_get function from the rdrop2 package as described here: https://github.com/karthik/rdrop2. Unfortunately it seems that the file is not loaded, however it takes a few seconds before the alternative text is shown so something is going on in the background (no error message or warning in the console). My token and dropbox setup should work, because if I try it outside of the shiny app, it loads the file perfectly.
Apologies that the code is not 100% reproducible as the token includes my personal dropbox authentication details...
ui.R
library(shiny)
shinyUI(fluidPage(
titlePanel("My app"),
sidebarLayout(
sidebarPanel(
selectInput("figure",
"Choose figure",
choices = list("file1","file2"),
selected = "file1")
),
mainPanel(
imageOutput("image")
)
)
))
server.R
library(shiny)
library(rdrop2)
token <- readRDS("droptoken.rds")
drop_acc(dtoken = token)
shinyServer(function(input, output) {
reactive({
drop_get(paste(input$figure, '.jpg', sep = ''))
})
output$image <- renderImage({
filename <- paste(input$figure, '.jpg', sep='')
list(src = filename,
alt = paste("Image name:", input$figure))
}, deleteFile = FALSE)
})
Upvotes: 1
Views: 1126
Reputation: 164
You need to call your reactive function within renderImage. Something similar to the following code worked in one of my shiny apps.
library(shiny)
library(rdrop2)
token <- readRDS("droptoken.rds")
drop_acc(dtoken = token)
shinyServer(function(input, output) {
myImage <- reactive({
drop_get(paste(input$figure, '.jpg', sep = ''))
})
output$image <- renderImage({
myImage()
filename <- paste(input$figure, '.jpg', sep='')
list(src = filename,
alt = paste("Image name:", input$figure))
}, deleteFile = FALSE)
})
EDIT: Alternatively, you could put drop_get code in renderImage.
library(shiny)
library(rdrop2)
token <- readRDS("droptoken.rds")
drop_acc(dtoken = token)
shinyServer(function(input, output) {
output$image <- renderImage({
drop_get(paste(input$figure, '.jpg', sep = ''))
filename <- paste(input$figure, '.jpg', sep='')
list(src = filename,
alt = paste("Image name:", input$figure))
}, deleteFile = FALSE)
})
Upvotes: 1