簡體   English   中英

r-用戶通過閃亮向數據框輸入值

[英]r - input value by user to dataframe via shiny

我正在構建一個允許用戶傳遞來自selectizeInputcheckboxInput的值以形成數據checkboxInput的應用。 我搜索了一段時間,發現這些源與我期望的類似:

  1. 可動手

它來自這里: https : //github.com/jrowen/rhandsontable 我的非常類似於此示例:

shiny::runGitHub("jrowen/rhandsontable",
                 subdir = "inst/examples/rhandsontable_portfolio")

但是我想使用閃亮的小部件將值傳遞給數據框。 它應該能夠添加/刪除行,如下例所示:

  1. 閃亮的孵化器

代碼在這里:

library("shiny")
library('devtools')
install_github('shiny-incubator', 'rstudio')
library("shinyIncubator")

# initialize data with colnames
df <- data.frame(matrix(c("0","0"), 1, 2))
colnames(df) <- c("Input1", "Input2")
    server = shinyServer(
      function(input, output) {
        # table of outputs
        output$table.output <- renderTable(
          { res <- matrix(apply(input$data,1,prod))
          res <- do.call(cbind, list(input$data, res))
          colnames(res) <- c("Input 1","Input 2","Product")
          res
          }
          , include.rownames = FALSE
          , include.colnames = TRUE
          , align = "cccc"
          , digits = 2
          , sanitize.text.function = function(x) x      
        )  
      }
    )

ui = shinyUI(
  pageWithSidebar(

    headerPanel('Simple matrixInput example')

,
sidebarPanel(

  # customize display settings    
  tags$head(
    tags$style(type='text/css'
               , "table.data { width: 300px; }"
               , ".well {width: 80%; background-color: NULL; border: 0px solid rgb(255, 255, 255); box-shadow: 0px 0px 0px rgb(255, 255, 255) inset;}"
               , ".tableinput .hide {display: table-header-group; color: black; align-items: center; text-align: center; align-self: center;}"
               , ".tableinput-container {width: 100%; text-align: center;}"
               , ".tableinput-buttons {margin: 10px;}"
               , ".data {background-color: rgb(255,255,255);}"
               , ".table th, .table td {text-align: center;}"

    )
  )
  ,
  wellPanel(
    h4("Input Table")
    ,      
    matrixInput(inputId = 'data', label = 'Add/Remove Rows', data = df)
    , 
    helpText("This table accepts user input into each cell. The number of rows may be controlled by pressing the +/- buttons.")
  )
)
,
mainPanel(
  wellPanel(
    wellPanel(
      h4("Output Table")
      ,
      tableOutput(outputId = 'table.output')
      ,
      helpText("This table displays the input matrix together with the product of the rows of the input matrix")
    )
  )
    )
  )
)
runApp(list(ui = ui, server = server))

用戶應從閃亮的小部件(如selectizeInputcheckboxInputtextInput輸入該值,並在用戶單擊我的actionButton將其傳遞給數據actionButton 我想要的功能與上述功能的組合非常相似,但我不知道該怎么做。 有什么建議么?

提前謝謝了。

盡管我最終沒有使用這兩個軟件包,但是效果很好:

library(shiny)

server = shinyServer(function(input, output, session){

  values <- reactiveValues()

values$DT <- data.frame(Name = NA,
                        status = NA,
                        compare = NA,
                        stringsAsFactors = FALSE)

newEntry <- observeEvent(input$addrow, {
    newLine <- c(input$textIn, input$boxIn, input$selectIn)
    values$DT <- rbind(values$DT, newLine)
})

newEntry <- observeEvent(input$revrow, {
  deleteLine <- values$DT[-nrow(values$DT), ]
  values$DT <- deleteLine
})

  output$table <- renderTable({
    values$DT
  })

})

ui = shinyUI(navbarPage(
  "Backtest System", inverse = TRUE, id = "navbar",
  tabPanel("Strategy",
           sidebarLayout(
             sidebarPanel(
               h4("Indicator"),
               textInput("textIn", "Text", "try"),
               checkboxInput("boxIn", "Box", TRUE),
               selectizeInput("selectIn", "Select", 
                              choices = c(">" = ">",
                                          ">=" = ">=",
                                          "<" = "<",
                                          "<=" = "<=")),
               actionButton("addrow", "Add Row"),
               actionButton("revrow", "Remove Row")
             ),
             mainPanel(
               tableOutput("table")
             )
           )
  )
  )
)
runApp(list(ui = ui, server = server))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM