Skip to content

Commit

Permalink
Development into master (#66)
Browse files Browse the repository at this point in the history
* Create functional add/delete buttons (#65)

Create successful implementation of add/delete btns

The data entry table can now accept requests to add/delete rows with the available buttons. Slightly reformat the UI for this change.

* Add CRAN status badge

Intend to release on CRAN in the future so adding badge now.
  • Loading branch information
NeuroShepherd authored Feb 16, 2024
1 parent 4d6905e commit 7fb01fd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 28 deletions.
44 changes: 16 additions & 28 deletions R/mod_data_entry.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ mod_data_entry_ui <- function(id){
ns <- NS(id)

tagList(
rhandsontable::rHandsontableOutput(ns("hottable")),
br(),
actionButton(ns("add_row"), "Add Row"),
actionButton(ns("delete_row"), "Delete Row")
box(width = 2,
actionButton(ns("add_row"), "Add Row"), br(), br(), actionButton(ns("delete_row"), "Delete Row"),
align = "center"
),
box(width = 10, rhandsontable::rHandsontableOutput(ns("hottable")))
)

}
Expand All @@ -26,34 +27,21 @@ mod_data_entry_server <- function(id){
moduleServer( id, function(input, output, session){
ns <- session$ns

values = reactiveValues()


probability_data = reactive({

if (!is.null(input$hottable)) {
entered_data = rhandsontable::hot_to_r(input$hottable)
} else {
if (is.null(values[["entered_data"]])) {

entered_data = data.frame(`Group 1 Probabilities` = rep(0,3),
`Group 2 Probabilities` = rep(0,3),
check.names = FALSE)

} else
entered_data = values[["entered_data"]]
}

values[["entered_data"]] = entered_data
entered_data

})
default_entry_rows <- getOption("ordinalsimr.default_entry_rows", default = 3)
entered_data = data.frame(`Group 1 Probabilities` = rep(0, default_entry_rows),
`Group 2 Probabilities` = rep(0, default_entry_rows),
check.names = FALSE)
reactive_data_vals <- reactiveVal(entered_data)

observeEvent(input$hottable, { reactive_data_vals(hot_to_r(input$hottable)) } )
observeEvent(input$add_row, { reactive_data_vals(rbind(reactive_data_vals(), 0)) })
observeEvent(input$delete_row, { reactive_data_vals(reactive_data_vals()[-nrow(reactive_data_vals()), ]) })


output$hottable <- rhandsontable::renderRHandsontable({

entered_data_2 = probability_data()
entered_data_2 = reactive_data_vals()


# https://stackoverflow.com/questions/58746194/shiny-and-rhandsontable-conditional-cell-column-formatting-based-on-column-sum
# not sure why I need to start at 1 and decrement from there, but it works...
Expand Down Expand Up @@ -103,7 +91,7 @@ mod_data_entry_server <- function(id){

})

return(probability_data)
return(reactive_data_vals)


})
Expand Down
1 change: 1 addition & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ knitr::opts_chunk$set(
<!-- badges: start -->
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![R-CMD-check](https://github.com/NeuroShepherd/ordinalsimr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/NeuroShepherd/ordinalsimr/actions/workflows/R-CMD-check.yaml)
[![CRAN status](https://www.r-pkg.org/badges/version/ordinalsimr)](https://CRAN.R-project.org/package=ordinalsimr)
<!-- badges: end -->

The goal of ordinalsimr is to ...
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
[![Lifecycle:
experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![R-CMD-check](https://github.com/NeuroShepherd/ordinalsimr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/NeuroShepherd/ordinalsimr/actions/workflows/R-CMD-check.yaml)
[![CRAN
status](https://www.r-pkg.org/badges/version/ordinalsimr)](https://CRAN.R-project.org/package=ordinalsimr)
<!-- badges: end -->

The goal of ordinalsimr is to …
Expand Down

0 comments on commit 7fb01fd

Please sign in to comment.