RinteRface / shinydashboardPlus

extensions for shinydashboard
https://shinydashboardplus.rinterface.com
Other
455 stars 77 forks source link

timelineBlock #13

Closed jiangnight closed 6 years ago

jiangnight commented 6 years ago

Hello,when i use timelinBlock i meet some thing confused about footer.

how can i output data element per line in timelineItem

`data = c("a","b","c") timelineBlock( timelineEnd(color = "danger"), timelineLabel(alldate[1], color = "teal"), timelineItem( title = "Item 1", icon = "gears", color = "olive", time = "now", footer =data )

`

DivadNojnarg commented 6 years ago

Hello,

could you send me an example in app.R please?

jiangnight commented 6 years ago

Hello,thanks for your help

library(shiny)
library(shinydashboard)
library(DT)
library(formattable)
library(readxl)
library(mongolite)
library(lubridate)
library(glue)
library(openxlsx)
library(shinydashboardPlus)
library(dashboardthemes)
library(shinyWidgets)
ui <-dashboardPagePlus(
    dashboardHeaderPlus(title="文件上传"),
    dashboardSidebar(
        sidebarMenu(
            menuItem("Echarts3",tabName = "echarts3",icon = icon("building")),
            menuItem("Echartsscatter", tabName = "scatter", icon = icon("bomb"))
        )
    ),
    dashboardBody(
        setShadow("box"),
        shinyDashboardThemes(
            theme = "blue_gradient"
        ),
        tabItems(
            tabItem(tabName = "echarts3",
                    fluidRow(
                        box(title = "updatefile",
                            width = 12,
                            fileInput("file1", "chosefile",
                                      width="100%",
                                      multiple = TRUE,
                                      buttonLabel = "点击选择文件",
                                      accept = c("text/csv",
                                                 "text/comma-separated-values,text/plain",
                                                 ".csv",
                                                 ".xlsx")),
                            actionButton("submit", "确认上传")
                        ),
                        box(
                            width = 6,
                            uiOutput("timeline")
                        ),
                        box(width = 6,
                            title = "detail",
                            DTOutput("contents")

                        )

                    )

            )

        )
    )

)

server <- function(input, output,session) {
    output$contents <- renderDT({
        req(input$file1)
        if(length(input$files1$datapath) == 1){
            insertlist <- list()
            insertlist$title <- input$file1$name
            insertlist$riqi <- Sys.Date()
            insertlist$year <- year(Sys.Date())
            insertlist$month <- month(Sys.Date())
            insertlist$data <- read_excel(input$file1$datapath,col_names = TRUE)
            my_db$insert(insertlist)
        }else{
            for(i in 1:length(input$file1$datapath)){
                insertlist <- list()
                insertlist$title <- input$file1$name[i]
                insertlist$riqi <- Sys.Date()
                insertlist$year <- year(Sys.Date())
                insertlist$month <- month(Sys.Date())
                insertlist$data <- read_excel(input$file1$datapath[i],col_names = TRUE)
                my_db$insert(insertlist)

            }
        }
        df <- data.frame("上传文件"=input$file1$name)
        datatable(df,options = list(dom = 'tr'),class = "hover")

    })

    ##timeline--------------------------------------------------------------------------

    refresh <- reactive({
        input$submit
        1
    })

    output$timeline <- renderUI({
        refresh()
        df <- data.frame(
            date=c(2018,2018,2018,2017,2016),
            title=c("hello","world","thank","you","DivadNojnarg")
        )
        disttime <- unique(df$date)
        timelineBlock(
            reversed = FALSE,
            timelineEnd(color = "danger"),
            timelineLabel(disttime[1], color = "teal"),
            timelineItem(
                title = "文件",
                icon = "gears",
                color = "olive",
                time = "now",
                footer = df[df$date==disttime[1],]$title
            ),
            timelineLabel(disttime[2], color = "orange"),
            timelineItem(
                title = "文件",
                icon = "paint-brush",
                color = "maroon",
                footer = df[df$date==disttime[2],]$title
            ),
            timelineStart(color = "gray")
        )

    })

}

shinyApp(ui = ui, server = server)
DivadNojnarg commented 6 years ago

Sorry but I don't understand your problem. What would you like to do exactly? Display everything in the same timelineItem or display each element in a unique timelineItem ... ?

jiangnight commented 6 years ago

oh, i want to make df group by date , and each group make a timelineItem , and titles in each group be contents of footer...

this is df

    df <- data.frame(
            date=c(2018,2018,2018,2017,2016),
            title=c("hello","world","thank","you","DivadNojnarg")
        )

when i have no good idea ,i must enumerate elements of group to realize the purpose


       footer = df[df$date==2018,]$title[1],df[df$date==2018,]$title[2],df[df$date==2018,]$title[3]
jiangnight commented 6 years ago

Hello, i have solve my problem by change some source code

mytimeItem <-
  function (...,
            icon = NULL,
            color = NULL,
            time = NULL,
            title = NULL,
            border = TRUE,
            footer = NULL)
  {
    data <- paste0(..., collapse = "<br><br>")
    cl <- "fa fa-"
    if (!is.null(icon))
      cl <- paste0(cl, icon)
    if (!is.null(color))
      cl <- paste0(cl, " bg-", color)
    itemCl <- "timeline-header no-border"
    if (isTRUE(border))
      itemCl <- "timeline-header"
    shiny::tags$li(
      shiny::tags$i(class = cl),
      shiny::tags$div(
        class = "timeline-item",
        shiny::tags$span(class = "time", shiny::icon("clock-o"), time),
        shiny::tags$h3(class = itemCl, title),
        shiny::tags$div(class = "timeline-body",
                        HTML(data)),
        shiny::tags$div(class = "timeline-footer", footer)
      )
    )
  }

now , i just give vector some arguments ,and thanks for your help.

timelineBlock(
            reversed = FALSE,
            timelineEnd(color = "danger"),
            timelineLabel(alldate[1], color = "teal"),
            mytimeItem(
                title = "文件",
                icon = "gears",
                color = "olive",
                time = "now",
                footer ="ads",
                c("hello","will","night")
            ),
            timelineLabel(alldate[2], color = "orange"),
            timelineItem(
                title = "文件",
                icon = "paint-brush",
                color = "maroon",
                footer = "file1","file2","adsfa"

            ),

image

DivadNojnarg commented 6 years ago

Very glad you solved id!

jiangnight commented 6 years ago

very thanks for you to develop this fancy package , it helps me a lot,thanks