在底部发布的几乎为MWE的代码中,我试图将自定义图像拉入绘图标题.在完整的应用程序中,用户点击图像以触发解释性模式对话.然而,在这种情况下,我无法在绘图头中获得要呈现的图像.在其他适合我的情况下,我使用renderUI(),但在本例中,我try 在renderPlot()函数中呈现图像.下面的图片比这些文字更能说明问题.在renderPlot()号楼里有没有办法做到这一点?

enter image description here

MWe代码:

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)

推荐答案

在这个场景中,我会使用SINY的actionLink:

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),
  column(12, align="center",
         actionLink(inputId = "explainBtn", label = strong("Weibull"), icon = NULL, br(), img(src = "https://images.plot.ly/language-icons/api-home/python-logo.png"))
  ),
  plotOutput("plot")
)

server <- function(input, output, session) {
  output$plot <- renderPlot({
    par(mar=c(5,4,0,2)+0.1) # reduce space above Plot
    curve(
      weibSurv(x, shape=input$shape,scale=1/0.03), 
      from=0, to=80,
    )
  })
  
  observeEvent(input$explainBtn, {
    showModal(modalDialog("do something useful"))
  })
  
}
shinyApp(ui, server)

Html相关问答推荐

从网络抓取中提取文本

srcset和大小总是下载最大的

如何修复与导航栏重叠的css网格?

使用css第n个子元素,如何迭代Y组中的X个元素?

使用响应迅速的网格系统,将两列保持在同一行,同时允许更多列用于更大的屏幕

仅向上扩展并以最大高度滚动的Div

未在抖动中播放的HTML音频||文本正在工作其他标记正在播放,但音频未播放

我希望创建一个对角手风琴与不同的内容(文本和图像)在其正常状态和其他元素悬停

带有图标和悬停过渡的CSS按钮

如何从elementor中的滑块中获取文本?

Angular MatBadge 在高于 99 时不显示完整数字

停止 Bootstrap 5 输入调整 CSS 网格单元的高度

使用 Thymeleaf 将图像水平居中

如何从 div 内的图像中删除填充而不从其他所有内容中删除填充?

如何垂直平移一个元素,使其新位置位于另外两个元素之间?

绝对类在另一个绝对类之上

W3Schools 幻灯片相同高度

那边界从何而来?

我应该如何使这个带有标签的隐藏复选框可访问

如何在 blazor 中单击单个按钮调用 2 个等待任务