R Shiny:shinyBS将navbarPage与bsModal一起使用 [英] R Shiny: Use navbarPage with bsModal by shinyBS
问题描述
我正在尝试在navbarPage中添加一个tabPanel,以便当您单击它时打开一个模式窗口,而不是一个新的选项卡.以下代码段无效,因为tabPanel没有id参数.
I'm trying to add a tabPanel in navbarPage so that when you click on it opens a modal window instead of a new tab. The snippet below is not valid because tabPanel does not have an id parameter.
library(shiny)
library(shinyBS)
shinyUI(fluidPage(
navbarPage("Sample App", id = "main_menu",
tabPanel("Open Modal", id = "moda")),
bsModal("modal1", "Example", "moda", p("This is a modal"))
)
如果我通过浏览器编辑生成的HTML代码,则可以通过更改以下行来实现
If I edit the generated HTML code from browser, I can make this possible by changing the line
<a href="#tab-9741-5" data-toggle="tab" data-value="Open Modal">Open Modal</a>
与
<a href="#" data-toggle="modal" data-target="#modal1">Open Modal</a>
在<li>
元素上.
任何想法如何做到这一点,或者至少如何覆盖闪亮的生成的html?
Any idea how to do this or at least how can I override the generated html from shiny?
推荐答案
一种解决方案是使用Javascript重写选项卡标题的属性.下面的JS代码找到标签标题链接,并重写其属性.
One solution is to use Javascript to rewrite the attribute for the tab title. The JS code below finds the tab title link, and rewrites its attributes.
library(shiny)
jsStr <- '$(document).ready(function(){
$("a[data-value=\'OpenModal\']").attr({
"href":"#",
"data-toggle":"modal",
"data-target":"#modal1"
});
})
'
ui <- shinyUI(fluidPage(
tags$head(tags$script(HTML(jsStr))),
navbarPage("title",
tabPanel("OpenModal")
),
bsModal("modal1", "Example", "moda", p("This is a modal"))
))
这篇关于R Shiny:shinyBS将navbarPage与bsModal一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!