gpt4 book ai didi

r - 使用 href 信息框作为操作按钮

转载 作者:行者123 更新时间:2023-12-01 21:47:55 25 4
gpt4 key购买 nike

我正在使用 Rshiny 构建一个应用程序

我有几个 infoBox,我想使用 href 选项在单击 infoBox 时弹出一个窗口.

我使用shinyBS作为弹出选项。这是我尝试过的:

valueBox(value=entry_01, icon = icon("users","fa-lg",lib="font-awesome"),href=shinyInput(actionLink,id='button_01',len=1,class="btn btn-default action-button",label=""),
width=NULL,color = "light-blue",subtitle = ""
)

但我发现,如果我们想链接到像 href = "http://stackoverflow.com/" 这样的外部网站,那么 href 选项就可以完美工作。但我不知道如何链接应用程序的内部链接。

编辑

我进行此编辑是因为我找到了一个解决方案,通过在 valueBox 输出列表中添加两个变量,使该框可单击并使其 Shiny 认为它是一个操作按钮。
- 类action-button
- id 允许我们使用observe 或observeEvent 来检测值框何时被单击。

这是一个可重现的示例

require(shiny)
require(shinydashboard)


header <- dashboardHeader(title="ReproductibleExample")
sidebar <- dashboardSidebar(disable=T)
body <- dashboardBody(valueBoxOutput("box_01"),
textOutput("print"))

ui <- dashboardPage(header, sidebar, body)


server<-shinyServer(function(input, output,session) {

output$box_01 <- renderValueBox({
entry_01<-20
box1<-valueBox(value=entry_01
,icon = icon("users",lib="font-awesome")
,width=NULL
,color = "blue"
,href="#"
,subtitle=HTML("<b>Test click on valueBox</b>")
)
box1$children[[1]]$attribs$class<-"action-button"
box1$children[[1]]$attribs$id<-"button_box_01"
return(box1)
})

output$print<-renderText({
print(input$button_box_01)
})
})



shinyApp(ui,server)

最佳答案

我决定改变方法。现在,我在值框的 substile 元素内包含了一个 actionbutton(或 actionLink),并创建了一个链接到此 actionButton 的 bsModal 元素。
如果您不熟悉ShinyBS打包它允许制作弹出窗口、工具提示等功能,而无需包含 HTML 或 java。

我遵循@Mikko Martila 的建议 Shiny: adding addPopover to actionLink这是一个可重现的示例来向您展示我的问题:

library("shiny")
library("shinydashboard")
library("shinyBS")

header <- dashboardHeader(title = "reporductible example")

body <- dashboardBody(valueBoxOutput("box_01"),
bsModal("modal", "foo", trigger = "", "bar"))
sidebar <- dashboardSidebar()
ui <- dashboardPage(header,sidebar,body,skin="green")
server = function(input, output, session) {
# ----- First info box synthesis menu
output$box_01 <- renderValueBox({
entry_01 <- "BlaBla"
valueBox(value=entry_01, icon = icon("users",lib="font-awesome"),
width=NULL,color = "blue",subtitle = HTML("<b>my substitle</b> <button id=\"button\" type=\"button\" class=\"btn btn-default action-button\">Show modal</button>")
)
})

observeEvent(input$button, {
toggleModal(session, "modal", "open")
})
}

runApp(list(ui = ui, server = server))

我使用 HTML() 选项将按钮添加到值框的副标题内。

这不是我真正想要的,但它确实有效。

您可以通过使用像这样的字幕来使用actionLink(看起来更好)来做到这一点:

subtitle=HTML("<b>my subtitle</b><a id=\"button_box_05\" href=\"#\" class=\"action-button\">
<i class=\"fa fa-question-circle\"></i>

</a>")

关于r - 使用 href 信息框作为操作按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34413137/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com