In the almost-MWE code posted at the bottom, I’m trying to pull a custom image into the plot header. In the full App the user clicks on the image in order to trigger an explanatory modal dialogue. However, I can’t get the image to render in the plot header in this case. In other cases where this works for me fine, I use renderUI()
, but in this case I’m trying to render the image inside the renderPlot()
function. Image below explains better than these words. Is there a way to do this inside renderPlot()
?
MWE code:
library(shiny)
library(survival)
### define function ###
weibSurv <- function(t, shape, scale) pweibull(t, shape=shape,scale=scale, lower.tail=F)
ui <- fluidPage(
selectInput("distSelect","Select distribution:",c("Weibull","Gamma")),
sliderInput('shape','Adjust shape:',min=0,max=3,step=0.1,value=1.5),
plotOutput("plot")
)
server <- function(input, output, session) {
output$plot <- renderPlot({
curve(
weibSurv(x, shape=input$shape,scale=1/0.03),
from=0, to=80,
main =
fluidRow(
paste(input$distSelect), # leave paste, actual App has more objects to include here
tags$button(
id = "explainBtn",
class = "btn action-button",
tags$img(src = "https://images.plot.ly/language-icons/api-home/python-logo.png")
)
)
)
})
}
shinyApp(ui, server)
2
Answers
For anyone who favors
renderUI
, here's a solution though I would defer to ismirsehregal'sactionLink()
solution above as it is cleaner.I’d use shiny’s
actionLink
in this scenario: