【发布时间】:2018-04-19 21:19:45
【问题描述】:
我正在尝试开发一个应用程序,用户可以在其中上传文件并准备文件。
因此,我设计了带有 2 个子菜单项的仪表板,称为加载和准备,如下所示。
在第一个选项卡中,我正在尝试由用户上传文件。
在第二个选项卡中,准备我想显示用户选择的文件中的列名。例如,如果我的数据框有列名(ID、日期、接受、拒绝),那么我希望它们列在准备选项卡中。
一旦列出,用户应该能够选择他想要的数据类型。
下面是我创建的仪表板的快照。
这是用户界面代码:
ui<-dashboardPage(
dashboardHeader(title = "Model"),
dashboardSidebar(
sidebarMenu(id="tabs",
menuItem("Data", tabName = "data", icon = icon("table"),startExpanded = TRUE,
menuSubItem("Load", tabName = "data1"),
menuSubItem("Prep", tabName = "prep")
),
menuItem("Visualisation",icon=icon("bar-chart-o"), tabName = "vis"),
menuItem("Result", icon=icon("cog"), tabName = "result")
)
),
dashboardBody(
tags$style(type="text/css",
".shiny-output-error { visibility: hidden; }",
".shiny-output-error:before { visibility: hidden; }"
),
tabItems(
tabItem(tabName = "data1",
fluidPage(
fluidRow(
fileInput("file1","Choose CSV File",
accept = c("text/csv",
"text/comma-seperated-values, text/plain",
".csv")
),
tags$hr(),
checkboxInput("header", "Header", TRUE),
radioButtons("sep","Separator",
choices=c(Comma=",",
semicolon=";",
Tab="\t"),
selected = ";")
),
mainPanel(
uiOutput("tb")
)
)),
#--------Sub menu Item 2-----------
tabItem(tabName = "prep",
h1("Preprocessing"),
fluidPage(
fluidRow(
uiOutput("loaded_tb"),
selectInput('data_option','Select Option',
label="Select the Variable",
list(
"Variable Attributes"="var_attr",
"Data Summary ='data_summary"
))
),
radioButtons("class_selection", label="Variables Modeification",
choices = list(Numeric="numeric",Factor="factor",
Character ="character",
Date="date"),
selected = "numeric"),
selectInput('date_format', "Select the Date Format",
list(
YMD ="ymd",
YDM ="ydm",
MYD ="myd",
DMY ="dmy",
DYM ="dym"
)),
tags$h5("Date Preview"),
verbatimTextOutput('date_preview'),
actionButton("var_modify", "Modify")
),
mainPanel(
uiOutput("Pre")
)
))
)
)
这是服务器代码:
server <- shinyServer(function(input,output){
data <- reactive({
file1 <- input$file1
if(is.null(file1)){return()}
read.csv(file = file1$datapath, sep=input$sep)
})
output$filedf <- renderTable({
if(is.null(data())){return()}
input$file1
})
output$sum <- renderTable({
if(is.null(data())){return()}
summary(data())
})
output$table <- renderTable({
if(is.null(data())){return()}
data()
})
output$tb <- renderUI({
if(is.null(data())){return()}
tabsetPanel(tabPanel("About file", tableOutput("filedf")),tabPanel("Data", tableOutput("table")),tabPanel("Summary", tableOutput("sum")))
})
#----- Data Preparation------
output$Pre <- renderUI({checkboxGroupInput(inputId = "select_vars",
choices = names(data))
})
data_sel <- reactive({
req(input$select_vars)
data_sel<- data()%>% select(input$select_var)
})
})
shinyApp(ui,server)
【问题讨论】:
-
谁能帮我解决这个问题?
-
请剥离您的可重现示例以使其尽可能小,有关提示,请参阅here。另外,我不清楚您的问题或目标是什么。
-
@Florian 我已经用我的仪表板设计图像和 UI 、服务器代码完全编辑了帖子。
-
我觉得你应该看看reactiveValues
-
是的,所以你可以反复读写来修改列。