如何解决闪亮的仪表板格式问题
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:",max = 5,value = 3,step = 1),numericInput('turnover','Total Turnover',value = 10),sliderInput('promoRate','Set Promo rate',value = 25,max = 100,step = 5),sliderInput('growthRate','Set growth rate',value = 0,min=0,max=100,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。)一旦出现表格并且我转到“模拟”选项卡,仪表板主体是否会相应更改并显示我填充的simulateAvgData设置?
dataSim函数来自顶部的源文件。我运行任何程序时都不会收到任何错误,因此正在寻找有关此闪亮的仪表板是否按预期工作的指导和意见。我是闪亮的仪表板软件包的新手。
解决方法
您在这里遇到了几个问题。您不需要在fileInput
中使用dashboardBody
语句。接下来,您可以在dashboardSidebar
内,在fileInput
的顶级(以下代码中的选项1)或第一个menuItem
的子级别中定义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",startExpanded = F,## data not displayed for this tabName
menuItem("Full_data",icon=icon("table")),fileInput("file",".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)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。