bs4DashBody( bs4TabItems( bs4TabItem( tabName ="item1", fluidRow( lapply(1:3, FUN =function(i){ bs4Sortable
( width =4, p(class="text-center", paste("Column", i)), lapply(1:2, FUN =function(j){ bs4Card( title = paste0("I am the ", j,"-th card of the ", i,"-th column"), width =12,"Click on my header")}))}))), bs4TabItem( tabName ="item2", bs4Card( title ="Card with messages", width =9, userMessages( width =12, status ="success", userMessage( author ="Alexander Pierce", date ="20 Jan 2:00 pm", src ="https://adminlte.io/themes/AdminLTE/dist/img/user1-128x128.jpg", side = NULL,"Is this template really for free? That's unbelievable!"), userMessage( author ="Dana Pierce", date ="21 Jan 4:00 pm", src ="https://adminlte.io/themes/AdminLTE/dist/img/user5-128x128.jpg", side ="right","Indeed, that's unbelievable!"
))))))
填充
bs4DashBody()
后效果如下:
7. 组装代码
最后,把上面每一个部分的代码套到框架里就得到了这个 bs4Dash 应用的完整代码:
library(shiny)library(bs4Dash)shiny::shinyApp( ui = bs4DashPage( old_school = FALSE, sidebar_collapsed = TRUE, controlbar_collapsed = TRUE, title ="Basic Dashboard", navbar = bs4DashNavbar( skin ="light", status ="white", border = TRUE, sidebarIcon ="bars", controlbarIcon ="th",fixed= FALSE, leftUi = bs4DropdownMenu( show = TRUE, align ="left", status ="warning", menuIcon ="envelope-open", src = NULL), rightUi = bs4DropdownMenu( show = FALSE, status ="danger", src ="https://www.google.fr", bs4DropdownMenuItem
( message ="message 1",from="Divad Nojnarg", src ="https://adminlte.io/themes/v3/dist/img/user3-128x128.jpg", time ="today", status ="danger", type ="message"), bs4DropdownMenuItem( message ="message 2",from="Nono Gueye", src ="https://adminlte.io/themes/v3/dist/img/user3-128x128.jpg", time ="yesterday", status ="success", type ="message"))), sidebar = bs4DashSidebar( skin ="light", status ="primary", title ="bs4Dash", brandColor ="primary", url ="https://www.google.fr", src ="https://adminlte.io/themes/AdminLTE/dist/img/user2-160x160.jpg", elevation =3, opacity =0.8, bs4SidebarUserPanel( img ="https://image.flaticon.com/icons/svg/1149/1149168.svg", text ="Welcome Onboard!"), bs4SidebarMenu( bs4SidebarHeader("Header 1"), bs4SidebarMenuItem("Item 1", tabName ="item1"
, icon ="sliders"), bs4SidebarMenuItem("Item 2", tabName ="item2", icon ="id-card"))), controlbar = bs4DashControlbar( skin ="light", title ="My right sidebar", sliderInput( inputId ="obs", label ="Number of observations:", min =0, max =1000, value =500), column( width =12, align ="center", radioButtons( inputId ="dist", label ="Distribution type:", c("Normal"="norm","Uniform"="unif","Log-normal"="lnorm","Exponential"="exp")))), footer = bs4DashFooter( copyrights = a( href ="https://twitter.com/divadnojnarg", target ="_blank","@DivadNojnarg"
), right_text ="2018"), body = bs4DashBody( bs4TabItems( bs4TabItem( tabName ="item1", fluidRow( lapply(1:3, FUN =function(i){ bs4Sortable( width =4, p(class="text-center", paste("Column", i)), lapply(1:2, FUN =function(j){ bs4Card( title = paste0("I am the ", j,"-th card of the ", i,"-th column"), width =12,"Click on my header")}))}))), bs4TabItem( tabName ="item2", bs4Card( title ="Card with messages", width =9, userMessages( width =12, status ="success", userMessage( author ="Alexander Pierce", date ="20 Jan 2:00 pm",
src ="https://adminlte.io/themes/AdminLTE/dist/img/user1-128x128.jpg", side = NULL,"Is this template really for free? That's unbelievable!"), userMessage( author ="Dana Pierce", date ="21 Jan 4:00 pm", src ="https://adminlte.io/themes/AdminLTE/dist/img/user5-128x128.jpg", side ="right","Indeed, that's unbelievable!"))))))), server =function(input, output){})
进阶
bootstrap 4 卡片
bs4Dash 也带来了许多 bootstrap 4 卡片特性。
Classic Cards
•
bs4Card()
fluidRow( bs4Card( title ="Closable card with dropdown", closable = TRUE, width =6, status ="warning", solidHeader = FALSE, collapsible = TRUE, label = bs4CardLabel( text =1, status ="danger", tooltip
="Hello!"), dropdownMenu = dropdownItemList( dropdownItem(url ="https://www.google.com", name ="Link to google"), dropdownItem(url ="#", name ="item 2"), dropdownDivider(), dropdownItem(url ="#", name ="item 3")), plotOutput("plot")), bs4Card( title ="Closable card with gradient", closable = TRUE, width =6, status ="warning", solidHeader = FALSE, gradientColor ="success", collapsible = TRUE, plotOutput("distPlot")), bs4Card( title ="Card with solidHeader and elevation", elevation =4, closable = TRUE, width =6, solidHeader = TRUE, status ="primary", collapsible = TRUE, plot_ly(z =~volcano)%>% add_surface()))
Social Cards
•
bs4UserCard()
和
bs4SocialCard()
fluidRow( bs4UserCard( src ="https://adminlte.io/themes/AdminLTE/dist/img/user1-128x128.jpg", status ="info", title ="User card type 1", subtitle ="a subtitle here", elevation =4,"Any content here"), bs4UserCard( type =2, src ="https://adminlte.io/themes/AdminLTE/dist/img/user7-128x128.jpg", status ="success", imageElevation =4, title ="User card type 2", subtitle ="a subtitle here", bs4ProgressBar( value =5, striped = FALSE, status ="info"), bs4ProgressBar( value =5, striped = TRUE, status ="warning", width ="20%"))), fluidRow( bs4SocialCard( title ="Social Card", subtitle ="example-01.05.2018", src ="https://adminlte.io/themes/AdminLTE/dist/img/user4-128x128.jpg","Some text here!", comments = tagList( lapply(X =1:10, FUN =function(i){ cardComment( src ="https://adminlte.io/themes/AdminLTE/dist/img/user3-128x128.jpg", title = paste("Comment", i), date ="01.05.2018", paste0("The ", i,"-th comment"))})), footer ="The footer here!"), bs4Card( title ="Box with user comment", status ="primary", userPost( id =1, src ="https://adminlte.io/themes/AdminLTE/dist/img/user1-128x128.jpg", author ="Jonathan Burke Jr.", description ="Shared publicly - 7:30 PM today","Lorem ipsum represents a long-held tradition for designers, typographers and the like.Some people hate it and argue for its demise, but others ignore the hate as they create awesome tools to help create filler text for everyone from bacon lovers to CharlieSheen fans.", userPostTagItems( userPostTagItem(bs4Badge("item 1", status ="warning")), userPostTagItem(bs4Badge("item 2", status ="danger")))), userPost(
id =2, src ="https://adminlte.io/themes/AdminLTE/dist/img/user6-128x128.jpg", author ="Adam Jones", description ="Shared publicly - 5 days ago", userPostMedia(src ="https://adminlte.io/themes/AdminLTE/dist/img/photo2.png"), userPostTagItems( userPostTagItem(bs4Badge("item 1", status ="info")), userPostTagItem(bs4Badge("item 2", status ="danger")))))), fluidRow( bs4Card( status ="primary", width =3, solidHeader = TRUE, cardProfile( src ="https://adminlte.io/themes/AdminLTE/dist/img/user4-128x128.jpg", title ="Nina Mcintire", subtitle ="Software Engineer", cardProfileItemList( bordered = TRUE, cardProfileItem( title ="Followers", description =1322), cardProfileItem( title ="Following", description =543), cardProfileItem( title ="Friends", description =13287)))), bs4Card( title ="Card with messages", width =9, userMessages( width =12, status ="success", userMessage( author ="Alexander Pierce", date ="20 Jan 2:00 pm", src ="https://adminlte.io/themes/AdminLTE/dist/img/user1-128x128.jpg", side = NULL,"Is this template really for free? That's unbelievable!"), userMessage( author ="Dana Pierce", date ="21 Jan 4:00 pm", src ="https://adminlte.io/themes/AdminLTE/dist/img/user5-128x128.jpg", side ="right","Indeed, that's unbelievable!"))))
Tab Cards
•
bs4TabCard()
fluidRow( column( width =6, bs4TabCard( id ="tabcard1", title ="A card with tabs", elevation =2, width =12, bs4TabPanel( tabName ="Tab 1", active = FALSE,"A wonderful serenity has taken possession of my entire soul, like these sweet mornings of spring which I enjoy withmy whole heart. I am alone,and feel the charm of existence inthis spot, which was created for the bliss of souls like mine. I am so happy,my dear friend, so absorbed in the exquisite sense of mere tranquil existence, that I neglect my talents. I should be incapable of drawing a single stroke at the present moment;and yet I feel that I never was a greater artist than now"), bs4TabPanel( tabName ="Tab 2", active = TRUE,"The European languages are members of the same family.Their separate existence is a myth.For science, music, sport, etc,Europe uses the same vocabulary.The languages only differ in their grammar, their pronunciation and their most common words.Everyone realizes why a new common language would be desirable: one could refuse to pay expensive translators.To achieve this, it would be necessary to have uniform grammar,