当开发一个大的Shiny应用程序时,即使我们以一致的风格正确缩进代码的每一行,ui.R也会变得非常混乱。
在R包shinydashboard
中,我们可以先在menuItems
中定义sidebarMenu
,然后在tabItem
处定义tabName
(在menuItems
中定义## ui.R ##
sidebar <- dashboardSidebar(
sidebarMenu(
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
menuItem("Widgets", icon = icon("th"), tabName = "widgets",
badgeLabel = "new", badgeColor = "green")
)
)
body <- dashboardBody(
tabItems(
tabItem(tabName = "dashboard",
h2("Dashboard tab content")
),
tabItem(tabName = "widgets",
h2("Widgets tab content")
)
)
)
# Put them together into a dashboardPage
dashboardPage(
dashboardHeader(title = "Simple tabs"),
sidebar,
body
)
)稍后在代码中。这对于整理代码非常有用。
以下是其官方网站的一个例子:
shinydashboard
然而,在我的实际工作中,我倾向于自己设计每一个网页,所以shinydashboard
不是我的选择。我怎样才能做# define the structure first
tabsetPanel(
tab1,
tab2
)
# then work on each tab
tab1 = tabPanel("tab1", ....),
tab2 = tabPanel("tab2", ....)
可以做的事情,比如
renderUI
我尝试使用uiOutput
功能,但效果不佳(您无法将tabsetPanel
直接放在 select mon,year,
combo,
registered,
forwardedbycmo,
clarification,
noaction,
disposed,mon_srno,undertaken
from monthly_activities
union
select extract('month' from actiondate) as mon,extract('year' from actiondate) as year,
extract('year' from actiondate)|| '-' ||to_char(to_timestamp (extract('month' from actiondate)::text, 'MM'), 'TMMon') as combo,
sum(case when actioncode = '00' then 1 else 0 end) as registered,
sum(case when actioncode = '4T' and fromorg='CMOFF' then 1 else 0 end) as forwardedbycmo,
sum(case when actioncode = '4D' and fromorg='CMOFF' then 1 else 0 end) as clarification,
sum(case when actioncode = '10' then 1 else 0 end) as noaction,
sum(case when actioncode = '50' then 1 else 0 end) as disposed,null as mon_srno,
sum(case when actioncode = '40' and fromorg='CMOFF' then 1 else 0 end) as undertaken
from actionhistory where extract(month from actiondate)=extract(month from current_date)
and extract(year from actiondate)=extract(year from current_date)
group by mon,year order by year,mon;
中)。有没有更好的方法呢?