【问题标题】:Shiny Dashboard formatting issue闪亮的仪表板格式问题
【发布时间】:2020-11-09 15:29:27
【问题描述】:
   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 函数来自顶部的源文件。当我运行任何东西时,我没有收到任何错误,因此寻找指导和输入来了解这个闪亮的仪表板是否按预期工作。我是来自闪亮的仪表板包的新手。

【问题讨论】:

    标签: r shiny shinydashboard


    【解决方案1】:

    这里有几个问题。在dashboardBody 中不需要fileInput 语句。接下来,在dashboardSidebar 中,您可以在menuItem 的顶层定义fileInput(下面代码中的选项1),或第一个menuItem 的子级别(下面的选项2)。无论哪种情况,您都需要有一个menuItem 和一个tabName,您希望在其中显示已读入的文件。读取输入文件后,您需要选择适当的选项卡以查看显示的数据。试试这个代码

    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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-03-01
      • 2017-08-17
      • 2015-04-22
      • 1970-01-01
      • 2019-02-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多