Title: | An Interactive Anatomography Widget for 'shiny' |
---|---|
Description: | An 'htmlwidget' of the human body that allows you to hide/show and assign colors to 79 different body parts. The 'human' widget is an 'htmlwidget', so it works in Quarto documents, R Markdown documents, or any other HTML medium. It also functions as an input/output widget in a 'shiny' app. |
Authors: | Robert Norberg [aut, cre], Sebastian Zapata-Tamayo [aut, ctb], Mehrun Huda [aut, ctb] , Moffitt Cancer Center [cph] |
Maintainer: | Robert Norberg <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.3 |
Built: | 2025-01-09 06:40:08 UTC |
Source: | https://github.com/robert-norberg/shinybody |
This widget visualizes an SVG-based human body, highlights specific body parts, and displays associated participant data.
human( gender = c("male", "female"), organ_df, select_color = "yellow", width = NULL, height = NULL, elementId = NULL )
human( gender = c("male", "female"), organ_df, select_color = "yellow", width = NULL, height = NULL, elementId = NULL )
gender |
One of "male" or "female" |
organ_df |
A data.frame with at least an
|
select_color |
The color that should be applied to organs with the "selected" state (activated by clicking the organ and deactivated by clicking again). |
width |
Widget width |
height |
Widget height |
elementId |
ID of the widget |
An object of class human
and class htmlwidget
.
example_organs <- c("brain", "eye", "heart", "stomach", "bladder") my_organ_df <- subset(shinybody_organs, organ %in% example_organs) my_organ_df$show <- TRUE my_organ_df$color <- grDevices::rainbow(nrow(my_organ_df)) my_organ_df$selected[1] <- TRUE my_organ_df$hovertext <- mapply( function(o, clr) htmltools::strong( tools::toTitleCase(o), style = paste("color:", clr) ), my_organ_df$organ, my_organ_df$color, SIMPLIFY = FALSE ) human(gender = "female", organ_df = my_organ_df)
example_organs <- c("brain", "eye", "heart", "stomach", "bladder") my_organ_df <- subset(shinybody_organs, organ %in% example_organs) my_organ_df$show <- TRUE my_organ_df$color <- grDevices::rainbow(nrow(my_organ_df)) my_organ_df$selected[1] <- TRUE my_organ_df$hovertext <- mapply( function(o, clr) htmltools::strong( tools::toTitleCase(o), style = paste("color:", clr) ), my_organ_df$organ, my_organ_df$color, SIMPLIFY = FALSE ) human(gender = "female", organ_df = my_organ_df)
Output and render functions for using human within Shiny applications and interactive Rmd documents.
humanOutput(outputId, width = "100%", height = "400px") renderHuman(expr, env = parent.frame(), quoted = FALSE)
humanOutput(outputId, width = "100%", height = "400px") renderHuman(expr, env = parent.frame(), quoted = FALSE)
outputId |
output variable to read from |
width , height
|
Must be a valid CSS unit (like |
expr |
An expression that generates a human |
env |
The environment in which to evaluate |
quoted |
Is |
A shiny.tag.list
object (in the case of humanOutput
) or a
shiny.render.function
object (in the case of renderHuman
).
if (interactive()) { library(shiny) male_organs <- shinybody::shinybody_organs$organ[shinybody::shinybody_organs$male] female_organs <- shinybody::shinybody_organs$organ[shinybody::shinybody_organs$female] ui <- function() { fluidPage( selectInput( inputId = "gender", label = "Select Gender", choices = c("male", "female"), multiple = FALSE, selected = "male" ), selectInput( inputId = "body_parts", label = "Select Body Parts to Show", choices = male_organs, multiple = TRUE, selected = male_organs[1:5] ), humanOutput(outputId = "human_widget"), verbatimTextOutput(outputId = "clicked_body_part_msg"), verbatimTextOutput(outputId = "selected_body_parts_msg") ) } server <- function(input, output, session) { observe({ g <- input$gender if (g == "male") { organ_choices <- male_organs } else { organ_choices <- female_organs } updateSelectInput( session = session, inputId = "body_parts", choices = organ_choices, selected = organ_choices[1:5] ) }) output$human_widget <- renderHuman({ selected_organ_df <- subset( shinybody::shinybody_organs, organ %in% input$body_parts ) selected_organ_df$show <- TRUE human( organ_df = selected_organ_df, select_color = "red" ) }) output$clicked_body_part_msg <- renderPrint({ paste("You Clicked:", input$clicked_body_part) }) output$selected_body_parts_msg <- renderPrint({ paste("Selected:", paste(input$selected_body_parts, collapse = ", ")) }) } shinyApp(ui = ui, server = server) }
if (interactive()) { library(shiny) male_organs <- shinybody::shinybody_organs$organ[shinybody::shinybody_organs$male] female_organs <- shinybody::shinybody_organs$organ[shinybody::shinybody_organs$female] ui <- function() { fluidPage( selectInput( inputId = "gender", label = "Select Gender", choices = c("male", "female"), multiple = FALSE, selected = "male" ), selectInput( inputId = "body_parts", label = "Select Body Parts to Show", choices = male_organs, multiple = TRUE, selected = male_organs[1:5] ), humanOutput(outputId = "human_widget"), verbatimTextOutput(outputId = "clicked_body_part_msg"), verbatimTextOutput(outputId = "selected_body_parts_msg") ) } server <- function(input, output, session) { observe({ g <- input$gender if (g == "male") { organ_choices <- male_organs } else { organ_choices <- female_organs } updateSelectInput( session = session, inputId = "body_parts", choices = organ_choices, selected = organ_choices[1:5] ) }) output$human_widget <- renderHuman({ selected_organ_df <- subset( shinybody::shinybody_organs, organ %in% input$body_parts ) selected_organ_df$show <- TRUE human( organ_df = selected_organ_df, select_color = "red" ) }) output$clicked_body_part_msg <- renderPrint({ paste("You Clicked:", input$clicked_body_part) }) output$selected_body_parts_msg <- renderPrint({ paste("Selected:", paste(input$selected_body_parts, collapse = ", ")) }) } shinyApp(ui = ui, server = server) }
A randomly generated dataset of patient details
patients
patients
patients
A data frame with 16 rows and 5 columns:
A unique patient identifier
"male" or "female"
Patient age
Patient height in inches
Patient weight in lbs
A list of the organs that shinybody can display
shinybody_organs
shinybody_organs
shinybody_organs
A data frame with 79 rows and 7 columns:
The name of the organ the row describes (must be unique)
Boolean. TRUE if the body part can be shown on the male avatar, FALSE otherwise.
Boolean. TRUE if the body part can be shown on the female avatar, FALSE otherwise.
Boolean. TRUE if the body part should be shown, FALSE if it should be hidden.
Boolean. TRUE if the body part should appear in a "selected" state, FALSE otherwise.
A character column or a column containing shiny.tag
objects. This will be the contents of the tooltip that appears when the organ
is hovered over. If absent, the tooltip will contain the title-cased name of
the organ (underscores replaced with spaces).
A character column indicating the color the organ should appear if shown.
A randomly generated dataset of tumors to use in examples
tumors
tumors
tumors
A data frame with 39 rows and 5 columns:
A unique patient identifier
A unique tumor identifier
The organ affected by the tumor
TRUE if the tumor is the patient's primary cancer site, otherwise FALSE
The stage of the tumor (I, II, or III)