Skip to content

Commit

Permalink
try as RMarkdown instead
Browse files Browse the repository at this point in the history
  • Loading branch information
ljwright committed Oct 14, 2024
1 parent 6ea1fac commit 7f011f3
Show file tree
Hide file tree
Showing 227 changed files with 7,111 additions and 589,265 deletions.
18 changes: 9 additions & 9 deletions Shiny/app.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
library(shiny)
library(DT)

df <- readRDS("smoking_items.Rds")

# Define UI
ui <- fluidPage(
titlePanel("Smoking Behaviour in Five British Cohort Studies"),
Expand Down Expand Up @@ -32,20 +34,18 @@ ui <- fluidPage(
server <- function(input, output, session) {

# Load data from the RDS file
df <- readRDS("smoking_items.Rds")

# Create a modal dialog to show full row content
observeEvent(input$table_rows_selected, {
req(input$table_rows_selected)

# Get the selected row (only one row can be selected)
selected_row <- df[input$table_rows_selected[1], , drop = FALSE]

# Create content for the modal dialog with line breaks
modal_content <- lapply(names(selected_row), function(col) {
paste0("<strong>", col, ":</strong><br>", selected_row[[col]], "<br><br>")
})

showModal(modalDialog(
title = "Full Item Details",
HTML(paste(modal_content, collapse = "")), # Display row as a paragraph with line breaks
Expand All @@ -56,12 +56,12 @@ server <- function(input, output, session) {

output$table <- renderDT({
datatable(df,
escape = FALSE,
escape = FALSE,
filter = 'top',
options = list(
pageLength = nrow(df),
pageLength = 500,
searchHighlight = TRUE,
scrollX = TRUE,
scrollX = TRUE,
autoWidth = TRUE,
dom = 'Bfrtip',
selection = 'single'
Expand All @@ -75,7 +75,7 @@ server <- function(input, output, session) {
file.copy("smoking_items.xlsx", file)
}
)

output$downloadFile2 <- downloadHandler(
filename = function() { "smoking_items.xlsx" },
content = function(file) {
Expand Down
42 changes: 42 additions & 0 deletions Shiny/database.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
title: "Smoking Behaviour in Five British Cohort Studies"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(shiny)
library(DT)
df <- readRDS("smoking_items.Rds")
```

```{r, echo = FALSE}
tabsetPanel(
# First tab - Introduction
tabPanel("Introduction",
br(),
includeMarkdown("introduction.md"),
br(),
HTML('<a href="smoking_items.xlsx" download>Download Database as Excel file</a>')
),
# Second tab - Interactive Table
tabPanel("Database",
br(),
HTML('<a href="smoking_items.xlsx" download>Download Database as Excel file</a>'),
br(), br(),
datatable(df,
escape = FALSE,
filter = 'top',
options = list(
pageLength = 500,
searchHighlight = TRUE,
scrollX = TRUE,
autoWidth = TRUE,
dom = 'Bfrtip',
selection = 'single'
)
)
)
)
```

3,494 changes: 3,494 additions & 0 deletions Shiny/database.html

Large diffs are not rendered by default.

Binary file removed Shiny/smoking_items.rds
Binary file not shown.
54 changes: 54 additions & 0 deletions Shiny/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<style>
/* Reset body and container margins and paddings */
body {
margin: 0;
padding: 0;
width: 100%;
}

/* Ensure headers have no top margin and a small bottom margin */
h1, h2, h3 {
margin-top: 0;
margin-bottom: 0.5em;
}

/* Style for tabset to remove default padding and margins */
.tabset {
margin: 0;
padding: 0;
width: 100%; /* Full width */
}

/* Style for tab panels */
.tab-panel {
margin: 0;
padding: 0; /* Remove padding */
width: 100%; /* Full width */
}

/* Additional styles for the tabset */
.tabset > .nav-tabs {
margin: 0; /* Remove margins from the tab navigation */
}

/* Override the container class to remove side margins */
.container {
width: 100%; /* Make the container full width */
padding: 0; /* Remove padding from the container */
}

/* If using Bootstrap, override the default Bootstrap styles */
.container-fluid {
width: 100%; /* Make fluid containers full width */
padding-left: 0; /* Remove padding */
padding-right: 0; /* Remove padding */
}

.main-container {
width: 100%;
max-width: unset;
}

</style>


1 change: 0 additions & 1 deletion docs/app.json

This file was deleted.

34 changes: 0 additions & 34 deletions docs/edit/index.html

This file was deleted.

3,518 changes: 3,492 additions & 26 deletions docs/index.html

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions docs/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
This Shiny app provides an interactive and searchable database of survey items related to smoking behaviour in five British cohort studies. Information about the items on smoking behaviour was collated for the paper [*Life Course and Cohort Changes in Smoking Behaviour*](https://osf.io/54w6q/) by Liam Wright, Harry Tattan Birch, Loren Kock, and David Bann.

The cohorts included are:

1. [The National Survey of Health and Development (NSHD)](https://doi.org/10.1093/ije/dyq231), a birth cohort of individuals born in mainland Britain in a single week of March 1946.
2. [The National Child Development Study (NCDS)](https://doi.org/10.1093/ije/dyi183), a birth cohort of individuals born in Britain in a single week of March 1958.
3. [The 1970 British Cohort Study (BCS70)](https://doi.org/10.1093/ije/dyac148), a birth cohort of individuals born in Britain in a single week of April 1970.
4. [Next Steps](https://doi.org/10.5334/ohd.16) (formerly, the Longitudinal Study of Young People in England), a cohort of English schoolchildren followed from age 13/14 and born in 1989/90.
5. [The Millennium Cohort Study (MCS)](https://doi.org/10.1093/ije/dyu001), a birth cohort of individuals born in the UK in 2000/02.


The database contains metadata about every item on smoking behaviour from the studies. Items cover cohort members and their partners, friends and family members (e.g., parents). The metadata included spans variable names, exact question (and answer) wording, the focal person of (and respondent to) a specific item, the 'universe' of participants who were asked an item, survey mode, and the name of the (Stata) file and the survey questionnaire file the data is stored in.

Except for the NSHD, the survey data can be downloaded for free from the [UK Data Service](https://ukdataservice.ac.uk/). Data from the NSHD are instead available via application on [UCL Skylark](https://skylark.ucl.ac.uk/Skylark). In due course, we will creat a *basket* of variables on Skylark so that researchers can easily find the relevant variables.

The database can be viewed on this website or alternatively downloaded as an Excel file using the button below. A narrative overview of the collection of items of smoking is provided in the Supplementary Information of the [*Life Course and Cohort Changes in Smoking Behaviour*](https://osf.io/54w6q/) paper. Given data collection in each of the cohorts is ongoing, a *live* version of this overview is also available at https://osf.io/54w6q/.

Our hope is that this database will facilitate further use of the cohort studies, particularly cross-cohort examinations given the large changes in smoking that have occurred in Britain since the 1950s. Each of the five cohorts contains incredibly rich data on participants additional to their smoking behaviour. This includes linkages with genetic and administrative data. We encourage researchers to explore these data further.

This website was created by Liam Wright. Please email [Liam](mailto:liam.wright@ucl.ac.uk) with any comments or questions you have. Thanks for reading.
Loading

0 comments on commit 7f011f3

Please sign in to comment.