【发布时间】:2021-08-20 16:21:12
【问题描述】:
我想在导航栏上放置一个电子邮件按钮。我查看了 stackoverflow 和网络,但除此之外我找不到任何可靠的东西-Add action button on the right side of navbar page。我得到的最接近的方法是使用 fluidRrow 和列放置,但在我的实际应用中看起来很麻烦。
目前,我已将按钮放置在我想要的位置,但是它没有反应。我知道我可以在ui.R-
a(actionButton(inputId = "an_email", label = "Contact",
icon = icon("envelope", lib = "font-awesome")),
href="mailto:xyz@email.us")
但不确定如何接受这个想法并前往server.R,如果有人可以帮助我,我将不胜感激。
library(shiny)
# library(markdown)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
navbarPage("Navbar!",
tabPanel("Plot"
),
tags$script(
HTML("var header = $('.navbar > .container-fluid');
header.append('<div style=\"float:right; padding-top: 8px\"><button id=\"sendemail\" type=\"button\" class=\"btn btn-primary action-button\" onclick=\"sendEmail()\">Contact</button></div>')")
)
)
)
server <- function(input, output, session) {
# not sure if I need an obserEvent here
observeEvent(input$sendemail,{cat("contact envoked")})
onclick("sendemail", runjs("window.open('mailto:xyz@email.us')"))
# Tried this approach also
#onclick("sendemail", runjs("function sendEmail() {
# var link = 'mailto:me@example.com';
# window.location.href = link;}"))
#}
runApp(shinyApp(ui= ui, server= server))
【问题讨论】:
标签: html r shiny shiny-server shinyjs