簡體   English   中英

閃亮的儀表板格式問題

[英]Shiny Dashboard formatting issue

   library(needs)
needs(
    shiny,
    ggplot2,
    tidyverse,
    shinydashboard,
    DT
)
source("~/functions.R",local = T)

# Define UI for application that draws a histogram
header = dashboardHeader(
    # tags$li(class = "dropdown",
    #         tags$style(".main-header {max-height: 80px}"),
    #         tags$style(".main-header .logo {height: 80px}")),
    #title = tags$img(src='logo.png',height='100',width='200')
    
)

sidebar = dashboardSidebar(
    menuItem("Full data",tabName="Data",icon=icon("table"),startExpanded = F,
             fileInput("file","Upload CSV files",multiple=TRUE,accept=("text/comma"))),
    menuItem(text = 'Simulate',tabName = 'simulate',icon=icon('chart-line'),
             helpText('Simulation Parameters'),
             radioButtons('type',"Please choose the type of analysis:",choices = list("Gender" = 1,"US Minority Status" = 2),selected = 1),
             sliderInput("numSims","Number of simulations:",min = 1, max = 10000,step = 1000,value = 10000),
             sliderInput("numYears","Number of years to simulate:",min = 1,max = 5,value = 3,step = 1),
             numericInput('turnover','Total Turnover', value = 10),
             sliderInput('promoRate','Set Promo rate', value = 25, min = 1, max = 100, step = 5),
             sliderInput('growthRate','Set growth rate',value = 0,min=0,max=100,step = 1),
             helpText('0% Growth Rate assumes a flat, constant headcount'),
             actionButton('go',label  = "Update"),width = 4)
)
body <- dashboardBody(
    tabItems(
        tabItem(
            tabName = 'data',
                fluidRow(wellPanel(
                    fileInput(
                        inputId = 'file',
                        label = "File Upload:",
                        accept = c("csv", ".csv")))),
                    wellPanel(DT::dataTableOutput('table'))),
        tabItem(
            tabName = 'simulate',
                fluidRow(
                    wellPanel(
                        DT:::dataTableOutput('simDataTable')
                ))
        )
        
        ))



ui = shinydashboard::dashboardPage(header,sidebar,body,skin='red')

server = server <- function(input, output) {
    options(shiny.maxRequestSize = 30 * 1024 ^ 2)
    
    

    dataset <- reactive({
        req(input$file)
        read.csv(input$file$datapath)  
        
    })
    
    output$table = renderDataTable(dataset(), filter = 'top',options = list(scrollX = TRUE))
    
    simulate = eventReactive(input$go,{
        req(input$numSims,input$type)
        x = dataset()
        temp = dataSim(x,type=input$type,
                       numSims = input$numSims)
    })
    
    simulateAvg = reactive({
        x = simulate()
        y = x %>% group_by(Role) %>% summarise(mean(freq))
    })
    
    output$simDataTable = renderDataTable(simulateAvg())
    
}



shinyApp(ui,server)

我在兩個問題上遇到了一些麻煩。

格式問題 1.) 閃亮儀表板的格式很奇怪。 側欄上的文字看起來非常緊湊,而不是其他閃亮的儀表板的樣子。 我不確定是什么問題。

2.) 上傳后,表格應該出現在儀表板主體上,但它沒有

3.) 出現表格后,我會轉到模擬選項卡,儀表板主體是否會相應更改並顯示我填充的模擬平均數據集?

dataSim 函數來自頂部的源文件。 當我運行任何東西時,我沒有收到任何錯誤,因此尋找指導和輸入以了解這個閃亮的儀表板是否按預期工作。 我是閃亮的儀表板包的新手。

你在這里有幾個問題。 您不需要在dashboardBody使用fileInput語句。 接下來,在dashboardSidebar ,您可以在menuItem的頂層(下面代碼中的選項 1)或第一個menuItem的子級別(下面的選項 2)定義fileInput 無論哪種情況,您都需要有一個帶有tabNamemenuItem ,您希望在其中顯示讀入的文件。讀取輸入文件后,您需要選擇適當的選項卡以查看顯示的數據。 試試這個代碼

header <- dashboardHeader()

### option 1:  fileInput at the first menuItem level
# sidebar <- dashboardSidebar(width=320,
#                             menuItem("Full data",tabName="Data",icon=icon("table"),startExpanded = F),
#                             fileInput("file","Upload CSV files",multiple=FALSE,accept=c("csv", ".csv"))
# )
### option 2 - fileInput as a subitem
sidebar <- dashboardSidebar(width=320,
                            menuItem("Full data",tabName="noData",icon=icon("table"),startExpanded = F,  ##  data not displayed for this tabName
                              menuItem("Full_data",tabName="Data", icon=icon("table")),
                              fileInput("file","Upload CSV files",multiple=FALSE,accept=c("csv", ".csv")))

)

body <- dashboardBody(
  tabItems(
    tabItem(
      tabName = 'Data',
      fluidRow(DTOutput('table')))
  ))

ui <- shinydashboard::dashboardPage(header,sidebar,body,skin='red')
server <- function(input, output, session) {

  data1 <- reactive({
    req(input$file)
    data <- read.csv(input$file$datapath,sep = ",", header = TRUE)
  })
  
  output$table <- renderDT(data1())
  
}

shinyApp(ui,server)

輸出

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM