【发布时间】:2016-02-25 16:15:17
【问题描述】:
我的ui.R函数如下图。
library(shiny)
shinyUI(pageWithSidebar(
headerPanel("Add Features"),
sidebarPanel(width=4,
fluidRow(
column(6, selectInput("features", label = h3("Features"),
choices = list("Feature1","Feature2","Feature3"), selected = "Feature1")),
br(),
br(),
column(6, numericInput("n", label="",min = 0, max = 100, value = 50)),
br(),
column(2, actionButton("goButton", "Add!"))
#column(3, submitButton(text="Analyze"))
)),
mainPanel(
verbatimTextOutput("nText"),
textOutput("text2")
)
))
我的server.R函数如下:
library(shiny)
shinyServer(function(input, output) {
selFeatures <- data.frame()
valFeatures <- data.frame()
# builds a reactive expression that only invalidates
# when the value of input$goButton becomes out of date
# (i.e., when the button is pressed)
ntext <- eventReactive(input$goButton, {
selFeatures <- rbind(selFeatures,input$features)
valFeatures <- rbind(valFeatures,input$n)
paste("The variables are",input$features,input$n)
paste("The variables are",selFeatures,valFeatures)
})
output$nText <- renderText({
ntext()
})
output$text2 <- renderText({
paste("You have selected", input$features)
})
})
我想要做的是要求用户输入一些变量。这里Feature1、Feature2 和Feature3。用户必须输入Feature1,但Feature2 和Feature3 是可选的。因此,这里用户选择一个特征,在numericInput 中输入它的值并按下按钮Add。在选择Feature1 后按下Add 时,用户可以选择提交表单或使用添加按钮添加功能2 和3。最后,我想用这三个变量来学习一个预测模型。如何收集数据框中的所有估算信息来处理它。此外,如果可能,在添加 selectBox 后将其从 Feature1 中删除。在按下添加按钮之前,我希望我的 UI 如下所示
按下添加按钮后应该如下所示。
这里的feature1不需要在选择框中,只是显示它已经添加的方式就可以了。
【问题讨论】:
标签: r user-interface shiny