在shinydashboard
中,可以创建menuItem()
s,它们是侧边栏中的标签。我希望能够使用标准input$foo
语法来轮询哪个选项卡处于活动状态。
然而,我无法这样做。我尝试引用menuItem()
的{{1}}或tabName
,但没有做任何事情。
有办法吗?
答案 0 :(得分:5)
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
using namespace std;
int main()
{
ifstream readchat;
readchat.open("chat.txt");
const int MAX = sizeof(readchat);
char line[MAX];
char *colon;
colon = strtok(line, ":");
while (!readchat.eof())
{
while (colon != NULL)
{
cout << line;
colon = strtok(NULL, ":");
}
}
system("pause");
return 0;
}
有可选的id参数,你可以使用它
sidebarMenu
在服务器端使用sidebarMenu(id="menu1",
menuItem("PointA_",tabName = "PointA")
)
完整的工作示例,打印input$menu1
或PointA
(点击有效)
PointB
找一个hack变种来做active + dropdown + input
使用额外的功能(得到想法here)
工作示例:
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(
title = "Shiny"
),
dashboardSidebar(
sidebarMenu(id="sbmenu",
menuItem("PointA_",tabName = "PointA") ,
menuItem("PointB_",tabName = "PointB")
)
),
dashboardBody(
tabItems(
tabItem("PointA",h1("a")),
tabItem("PointB",h1("b"))
)
)
)
server <- function(input, output) {
observe(print(input$sbmenu))
}
shinyApp(ui,server)
我不知道有关儿童等的记录。
但如果你喜欢它们之间的差异 你可以看到menuItem和menuItem + additionlal元素:
library(shiny)
library(shinydashboard)
convertMenuItem <- function(mi,tabName) {
mi$children[[1]]$attribs['data-toggle']="tab"
mi$children[[1]]$attribs['data-value'] = tabName
if(length(mi$attribs$class)>0 && mi$attribs$class=="treeview"){
mi$attribs$class=NULL
}
mi
}
ui <- dashboardPage(
dashboardHeader(
title = "Shiny"
),
dashboardSidebar(
sidebarMenu(id="sbmenu",
convertMenuItem(menuItem("PointA_",tabName="PointA", selected=TRUE,
checkboxInput("tc", "Test check", value=FALSE)
),'PointA') ,
convertMenuItem(menuItem("PointB_",tabName="PointB",checkboxInput("tc2", "Test check", value=FALSE)
),'PointB')
)
),
dashboardBody(
tabItems(
tabItem("PointA",h1("a")),
tabItem("PointB",h1("b"))
)
)
)
server <- function(input, output) {
observe({
print(input$sbmenu)
})
}
shinyApp(ui,server)
因为您看到aa=menuItem("PointA_",tabName="PointA", selected=TRUE,
checkboxInput("tc", "Test check", value=FALSE)
)
aa1=menuItem("PointA_",tabName="PointA", selected=TRUE)
> aa
<li class="treeview">
<a href="#shiny-tab-PointA">
<span>PointA_</span>
<i class="fa fa-angle-left pull-right"></i>
</a>
<ul class="treeview-menu">
<div class="form-group shiny-input-container">
<div class="checkbox">
<label>
<input id="tc" type="checkbox"/>
<span>Test check</span>
</label>
</div>
</div>
</ul>
</li>
> aa1
<li>
<a href="#shiny-tab-PointA" data-toggle="tab" data-value="PointA" data-start-selected="1">
<span>PointA_</span>
</a>
</li>
有aa1
,您需要将其添加到data-toggle="tab" data-value="PointA"
但是有aa
(我试图在检查中删除此类以检查更改的内容),您需要将其删除。
关于孩子,你可以在Rstudio的环境视图中看到