我ui.R
函數添加UI元素,並收集它們的輸入的數據幀是如下所示。動態閃亮
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
。當Add
是選擇Feature1
後按壓時,用戶可以選擇提交表單或添加使用添加按鈕特徵2和3。我最後想要用這三個變量來學習預測模型。我如何收集數據框中的所有估算信息來處理它。另外,如果可能的話已經被添加後從selectBox
刪除Feature1
。我想我的UI看起來像下面按添加按鈕
之前,它應該看起來像按下添加按鈕後,以下。
這裏的優點1不必在選擇框,只是一個以顯示它已被添加是好的方式。
如何使功能和可變等構成的數據幀: 特徵1 \ t特點2 \ n 55.45 \ t 77.68 \ n 把它分配給某個變量例如名字和陰謀barplot? – discipulus
我已經添加了如何在data.frame中獲取值。 –
對不起,但又一次。一旦我輸入了第一個功能的值,並且當按下Add按鈕時,第一個功能中的值就會丟失,那麼在分析按下之前如何使該永久值保持不變。 – discipulus