How to Align Leflet Main Panel to the Right - r

I am trying to get my mainpanel, a base leaflet map, to the right of the sidebar. It seems to align with the side bar panel and I am unsure why. I have attached my entire UI in hopes some one can see why my map is positioned above the side bar panel. I have also attached a picture of what the app looks like. Do I need to include a fluid row argument for the mainpanel?
map UI
ui <- fluidPage(
# Application title ----
titlePanel("Moorea Coral Reef LTER"),
sidebarLayout(
sidebarPanel(),
mainPanel(img(src = "mcr_logo.png", height = 60, width = 150, align = "right"),
img(src = "lter_logo.png", height = 60, width = 70, align = "right"),
img(src = "nsf_logo.png", height = 60, width = 60, align = "right"))),
# Navigatition bar ----
navbarPage("App Title",
#home page ----
tabPanel("Home",
img(src = "mcr_logo.png", height = 60, width = 150, align = "center"),
p("The Moorea Coral Reef (MCR) LTER site, established in 2004, is an interdisciplinary, landscape-scale program whose goal is to advance understanding of key mechanisms that modulate ecosystem processes and community structure of coral reefs through integrated research, education and outreach. Our site is the coral reef complex that encircles the 60 km perimeter of Moorea (17°30'S, 149°50'W), French Polynesia."),
p("A fundamental goal of the the Moorea Coral Reef (MCR) LTER site is to advance understanding that enables accurate forecasts of the behavior of coral reef ecosystems to environmental forcing. To this end we seek to understand the mechanistic basis of change in coral reefs by: (i) elucidating major controls over reef dynamics, and (ii) determining how they are influenced by the major pulse disturbances (e.g., cyclones, coral bleaching, coral predator outbreaks) and local press drivers (e.g., fishing, nutrient enrichment) to which they are increasingly being subjected, against a background of slowly changing environmental drivers associated with global climate change and ocean acidification.")),
#spatial page ----
navbarMenu("Spatial",
#spatial map ----
tabPanel(title = "Map",
mainPanel(leafletOutput(outputId = "leaflet_base",
width = 900,
height = 500), position = c("right")),
sidebarLayout(
fluidRow(
#leaflet map inputs
column(12, sidebarPanel(width = 2,
# Code block for incorporating more years of data
#pickerInput(inputId = "Year",
#label = "Select a Year:",
#choices = c("2016",
#"2017",
#"2018"),
#multiple = FALSE,
#width = 80),
pickerInput(inputId = "Month",
label = "First, Select Month:",
choices = c("January",
"May",
"July"),
selected = "",
multiple = F,
options = pickerOptions(title = "Select Month"),
width = 150),
pickerInput(inputId = "Variable",
selected = "",
multiple = F,
label = "Now, Select Variable:",
choices = c("Percent Nitrogen",
"Isotopic Nitrogen"),
options = pickerOptions(title = "Select Variable"),
width = 150)))),
fluidRow(
column(12, sidebarPanel(width = 2,
pickerInput(inputId = "Additional",
label = "Select Another Layer:",
choices = c("Percent Coral Bleached",
"Predicted Sewage",
"Bathymetry"),
selected = NULL,
multiple = F,
options = pickerOptions(title = "Select Additonal"),
width = 150),
pickerInput(inputId = "Other",
label = "Select an Add on:",
choices = c("LTER Sites",
"Observations",
"Sites & Observations"),
selected = NULL,
multiple = F,
options = pickerOptions(title = "Select Add On"),
width = 150),
checkboxGroupButtons(inputId = "Clear",
label = "Remove Layers",
choices = c("Clear"))))))),
#spatila metadata ----
tabPanel("Metadata")),
#Temporal page ----
navbarMenu("Temporal",
#figures by variable panel ----
tabPanel("Figures by Variable",
(pickerInput(inputId = "Temp_Variable",
label = "Select a Variable",
# choices = c("Crown of Thorns",
# "Coral Cover",
# "Fish Biomass",
# "Algae"),
choices = c("Mean Coral Cover" = "mean_coral_cover",
"Mean Algae Cover" = "mean_algae_cover",
"Mean Fish Biomass" = "mean_biomass_p_consumers",
"COTS Density" = "cots_density"),
multiple = FALSE)),
plotOutput(outputId = "faceted_plot")),
#figures by site panel ----
tabPanel("Figures by Site",
sidebarPanel(checkboxGroupInput(inputId = "site",
label = h4("Choose your Site"),
selected = "LTER 1",
choices = list("Site 1" = "LTER 1",
"Site 2" = "LTER 2",
"Site 3" = "LTER 3",
"Site 4" = "LTER 4",
"Site 5" = "LTER 5",
"Site 6" = "LTER 6"))),
mainPanel(plotOutput(outputId = "variables_by_site_plot"))),
#temporal metadata ----
tabPanel("Metadata")),
)
)

Related

How can I facet wrap for specific categorical values of multiple variables in Shiny?

as part of my research, I'm designing a Shiny app that allows visualization of a big pile of data. However, right now I'm working on the base of the app. For my app, I want the user to facet wrap just for specific categorical values of a variable. I'm working on a meta-analysis so I'm sure the number of categorical values will increase. Therefore, it would be much easier to look at a few values instead of all of them. Anyways, this is how my data looks like:
ABXID | ANIMALID | TIME | TLD | DV | DOSEMGKG | SPECIES | SUBSPECIES | AGE | PLATFORM | MUTATION
I know there's a lot of data, but it's all useful. So, for example the platform variable has different values, three to be exact: Duobody, Hexabody and Bispecific. I want the user to choose what type of antibody platform they want to be displayed and even more than just 1. Not only will I be doing this for PLATFORM, but also for the other variables, allowing the user to really see what they want. My Shiny app looks like this:
Note: I have only written the conditionPanels for PLATFORM and MUTATION, because I think it would be easy to see if it would work and if anyone could help me.
ui <- fluidPage(
tabsetPanel(tabPanel("Tab 1",
titlePanel("Shiny App: Concentration vs Time Graphs"),
sidebarLayout(
mainPanel("Concentration vs Time graphs", plotOutput(outputId = "plot")),
sidebarPanel(helpText("This app is developed to visualize pharmacokinetic data of different antibodies..."),
selectInput(
inputId = "study",
label = "Include study:",
choices = c("GLP Toxicity" = "ME1044-011", "Dose Range Finding", "Single Dose", "Repeat Dose"),
selected = "ME1044-011",
multiple = T
),
selectInput(
inputId = "x",
label = "X-axis:",
choices = c("Time" = "TIME", "TLD"),
selected = "Time"
),
selectInput(
inputId = 'column',
label = "Columns for:",
choices = c("Dose mg/kg" = "DOSEMGKG", "Species" = "SPECIES", "Antibody" = "ABXID", "Subspecies" = "SUBSPECIES", "Age" = "AGE", "Animal ID" = "ANIMALID"),
selected = "DOSEMGKG"
),
selectInput(
inputId = 'row',
label = "Rows for:",
choices = c("Dose mg/kg" = "DOSEMGKG", "Species" = "SPECIES", "Antibody" = "ABXID", "Subspecies" = "SUBSPECIES", "Age" = "AGE", "Animal ID" = "ANIMALID", "Platform" = "PLATFORM"),
selected = "ABXID"
),
conditionalPanel(
condition = "input.row == 'PLATFORM'",
selectInput(
inputId = 'platform',
label = "Choose platform(s)",
choices = c("Hexabody", "Duobody", "Bispecific"), multiple = T
)
),
conditionalPanel(
conditoin = "input.row == 'Mutation'",
selectInput(
inputId = 'mutation',
label = "Choose mutation(s):",
choices = c('M1', "M2", "M3"), multiple = T
)
),
selectInput(
inputId = "group",
label = "Group by:",
choices = c("Dose mg/kg" = "DOSEMGKG", "Species" = "SPECIES", "Antibody" = "ABXID", "Subspecies" = "SUBSPECIES", "Age" = "AGE", "Animal ID" = "ANIMALID"),
selected = "ANIMALID"
),
sliderInput(
inputId = 'trange',
label = "Time range:",
min = 0,
max = 1704,
value = c(0, 1704 )
)
))
)),
tabsetPanel(tabPanel("Tab 2",
titlePanel("Tab 2"),
sidebarLayout(
mainPanel("Plot #2", plotOutput(outputId = "plot2")),
sidebarPanel(helpText("Whatever text..."),
selectInput(
inputId = 't',
label = "Example",
choices = c("#1", "#2", "#3"),
selected = "#1"
)
)
)))
)
This is the server:
server <- function(input, output, session){
output$plot <- renderPlot({
ggplot(data = df, aes_string(x = input$x, y = "DV", col = input$group)) + xlab("Time") + ylab("Concentration (ug/mL)") +
geom_point() + facet_grid(get(input$row) ~ get(input$column)) + scale_x_continuous(limits = input$trange) +
scale_color_viridis(discrete = T) + theme_bw() })
}
shinyApp(ui = ui, server = server)
Anyways, I really hope someone can help me with this question, as I'm fairly new to Shiny and still am learning things. So with the conditionPanel, a selectInput will appear if the user clicks on the variable, allowing them to choose what value they want to be displayed. That's how I want them to use the app. I hope the helpful readers get my question!
I have tried facet_wrap(), but that is showing me all the values of course. I'm not familiar with other options. Anyways, I hope I can just facet_wrap() for specific values of a variable that the user has chosen, even if it's more than 1.

Shiny: how to use checkBoxGroupInput() to reactively change a bar chart

I'm pretty new to shiny and am struggling on how to use check boxes to update values in a bar chart. The idea I'm after is when a user ticks on a check box, a numerical value is generated that will be added to an aggregate from other inputs to make a bar chart. Here is the code I have gotten to work so far:
library(shiny)
ui <- fluidPage(
titlePanel("TCO Calculator"),
mainPanel(
sidebarPanel(
helpText("Product 1 information:"),
numericInput(
inputId = "price_1",
label = "Purchase Price",
value = "0",
min = 0,
width = '50%'
),
numericInput(
inputId = "install_1",
label = "Installation cost",
value = "0",
min = 0,
width = '50%'
),
selectInput("disposal_1", "Disposal Cost",
choices = list(Buyback = (10),
Dump = (30),
Reuse = (5)),
width = '50%'),
checkboxGroupInput("maint_1", "Maintenance:",
choices = c("Waxing",
"Stripping", "Burnishing"),
selected = NULL)
),
sidebarPanel(
helpText("Product 2 information:"),
numericInput(
inputId = "price_2",
label = "Purchase Price",
value = "0",
min = 0,
width = '50%'
),
numericInput(
inputId = "install_2",
label = "Installation cost",
value = "0",
min = 0,
width = '50%'
),
# make list?
selectInput("disposal_2", "Disposal Cost",
choices = list(Buyback = (10),
Dump = (30),
Reuse = (5)),
width = '50%'),
checkboxGroupInput("maint_2", "Maintenance:",
choices = NULL,
selected = NULL,
inline = FALSE,
width = NULL,
choiceNames = c("Waxing",
"Stripping", "Burnishing"),
choiceValues = c(10, 20, 40))
),
plotOutput("costPlot")))
server <- function(input, output, session) {
# aggregate inputs into reactive bar chart values.
select_price <- reactive({
c(input$price_1 + input$install_1
+ as.numeric(input$disposal_1),
input$price_2 + input$install_2 +
as.numeric(input$disposal_2))
})
# Bar chart.
my_bar <- output$costPlot <- renderPlot({
barplot(select_price(),
beside = T,
border=F,
las=2 ,
col=c(rgb(0.3,0.1,0.4,0.6) ,
rgb(0.3,0.5,0.4,0.6)) ,
space = 3,
ylab = "Total cost per square foot, US Dollar")
abline(v=c(4.9 , 6.1) , col="grey")
legend("top", legend = c("Product 1", "Product 2" ),
col = c(rgb(0.3,0.1,0.4,0.6),
rgb(0.3,0.5,0.4,0.6)),
bty = "n",
pch=20 , pt.cex = 4,
cex = 1.6, horiz = FALSE,
inset = c(0.05, 0.05))
my_bar
})
}
shinyApp(ui = ui, server = server)
I've been successful with the numericInput and selectInput stuff so far, I am having trouble putting together a concise way to include check boxes (with corresponding numeric values) into a reactive function that I can path into select_price(), like I have done with the numeric and selectBox stuff. Things go sideways when I try to map from other examples. I feel like there is an elegant, or in least working solution that exists. Any insight towards how to solve this would be so appreciated, thanks!
I am not sure whether this entirely solves all your problems but try this:
For maint_2, you correctly separate choiceNames and choiceValues. For maint_1 you dont't
checkboxGroupInput("maint_1", "Maintenance:",
choices = NULL,
selected = NULL,
choiceNames = c("Waxing", "Stripping", "Burnishing"),
choiceValues = c(10, 20, 40))
Then you can add input$maint_1 and input$maint_2 to your reactive (also wrapped in as.numeric(). I also use sum for + as you don't have a default for input$maint_1 and input$maint_2. sum evaluates this to 0 while + throws an error.
select_price <- reactive({
c(sum(input$price_1, input$install_1, as.numeric(input$disposal_1), as.numeric(input$maint_1)),
sum(input$price_2, input$install_2, as.numeric(input$disposal_2), as.numeric(input$maint_1)))
})

Filters in Mainpanel Horizontally

I'm trying to build Rshiny app, i have 3 tabs, but my problem is in the first one, I have 2 filters for this page "Country" and "Package" and i want to show in the top of main panel both filters but horizontally, i mean, Package should be in the right part of Country filter, How can i modify my current code to show both filters in one line?, Thanks !!
shinyAppui <- tagList(
useShinyjs(),
navbarPage(
title = "Alternative Risk Transfer - Parametric Weather Solutions",
id = "navbar",
tabPanel(title="Map",
value= "_map",
sidebarLayout(
sidebarPanel( width = NULL, height = NULL
# Filter for country
# pickerInput(inputId = "country_", label = strong(" Select Country"),
# choices = unique(Stations_static$Country), "Labels",
# options = list(`live-search` = TRUE)),
#
# # Filter for package
# uiOutput("data_filtered_country")
#
),
mainPanel(
pickerInput(inputId = "country_", label = strong(" Select Country"),
choices = unique(Stations_static$Country), "Labels",
options = list(`live-search` = TRUE), inline = TRUE),
uiOutput("data_filtered_country"),
leafletOutput("map_stations",width="150%",height="550px"),
DT::DTOutput("table_map",width="150%",height="550px")
)),
fluidRow(
style = "border-top: 1px solid; border-color: #A9A9A9; padding-top: 10px;padding-bottom: 10px;",
column(width = 8),
column(width = 2),
column(
width = 2,
style = "padding-left: 0px;",
actionButton(
inputId = "showTabRiskQuantification",
label = "Static data updated as of June 2020",
width = '100%'
)
)
)
), # ends tab panel
As #YBS said in the comment when you want to place objects in the same row you should use the fluidRow(column(),column(),...) structure. This will make your dashboard responsive as well. In this case it would look like this.
fluidRow(
column(
width = 3,
pickerInput(inputId = "country_", label = strong(" Select Country"),
choices = unique(Stations_static$Country), "Labels",
options = list(`live-search` = TRUE), inline = TRUE)
),
column(
width = 3,
uiOutput("data_filtered_country")
)
)
where you can play around with different values for width to get the spacing you want.

conditional panel where condition is length of input

I'm having trouble understanding why my condition input.wave1.length > 1 does not work.
What I would like happen is for the checkbox "Overall Curve" to not appear unless input$loess AND if there are more than 1 items checked in the either Wave 1 or Wave 2 accordions.
I don't see what I'm doing wrong. Is there a condition in javascript that will make this work or can this be done with R script?
my app:
library(shiny)
library(shinydashboard)
library(bsplus) #accordion
#########define waves##########
wave1 <- c(
"Cayuga", "Columbia", "Erie", "Greene",
"Lewis", "Putnam", "Suffolk", "Ulster"
)
wave2 <- c(
"Broome", "Chautauqua", "Cortland", "Genesee",
"Monroe", "Orange", "Sullivan", "Yates"
)
ui <- dashboardPage(
dashboardHeader(title = "Example"),
dashboardSidebar(
tags$h4("waves:", style = "margin: 5px;"),
bs_accordion(id = "waves") %>%
#use the entire heading panel as a link instead of just title
bs_set_opts(use_heading_link = TRUE) %>%
bs_append(
title = "Wave 1",
content = checkboxGroupInput(inputId = "wave1", label = NULL,
choices = c(wave1, "All Wave 1"),
selected = "Cayuga")
) %>%
bs_append(
title = "Wave 2",
content = checkboxGroupInput(inputId = "wave2", label = NULL,
choices = c(wave2, "All Wave 2"))
),
br(),
#LOESS CURVE ####
checkboxInput(inputId = "loess", label = "Display Loess Curve",
value = FALSE),
uiOutput("loess_a"),
# uiOutput("loess_overall"),
conditionalPanel(condition = "input.loess == TRUE & input.wave1.length > 1", # should include selected > 1
checkboxInput(inputId = "loessGrouped", label = "Overall Curve",
value = TRUE)
)
),
dashboardBody(
tags$style(HTML('.checkbox label{color: red;}'))
)
)
server <- function(input, output, session) {
# conditional loess smoother #######
output$loess_a <- renderUI({
req(input$loess)
conditionalPanel(condition = "input.loess == TRUE",
sliderInput(inputId = "smoothing", label = NULL,
min = 0, max = 1, value = 1, step = 0.1))
})
}
shinyApp(ui = ui, server = server)
To work with either Wave 1 or Wave 2 accordions having more than 1 item checked, you can use the following:
conditionalPanel(condition = "input.loess == 1 & (input.wave1.length > 1 || input.wave2.length > 1)", # should include selected > 1
checkboxInput(inputId = "loessGrouped", label = "Overall Curve",
value = TRUE)
)
In addition, you still need to make input.loess == 1 on the server side

Align three elements on Shiny dashboard

I try to put properly three elements on my Shiny dashboard
# User interface
ui <- fluidPage(theme = shinytheme("united"),
titlePanel("Crimes in Washington, DC (2017)"),
fluidRow(column(4,
selectInput("offenceInput", "Type of Offence",
choices =
sort(unique(incidents$OFFENSE)),
selected =
sort(unique(incidents$OFFENSE)),
multiple = TRUE),
selectInput("methodInput", "Method of Offence",
choices =
sort(unique(incidents$METHOD)),
selected =
sort(unique(incidents$METHOD)),
multiple = TRUE),
selectInput("shiftInput", "Police Shift",
choices =
sort(unique(incidents$SHIFT)),
selected =
sort(unique(incidents$SHIFT)),
multiple = TRUE),
selectInput('background', 'Background',
choices = providers,
multiple = FALSE,
selected = 'Stamen.TonerLite'),
dateRangeInput('dateRange',
label = 'Date',
start = as.Date('2017-01-01') ,
end = as.Date('2017-12-31')
)
),
column(10,
dataTableOutput('my_table'),
column(12,
leafletOutput(outputId = 'map', height = 600)
)
)
))
My map goes somewhere else, I tried different options. Just need map in a proper right top corner and a table below.
Here I have put all selectInput fields in left panel, map in right panel and my_table below these two panels. Trick is that column's 1st parameter should add to 12 (i.e. 4+8 in case of top panel and 12 in case of bottom panel).
ui <- fluidPage(fluidRow(column(4,
selectInput(...),
selectInput(...),
selectInput(...),
selectInput(...),
dateRangeInput(...)),
column(8,
leafletOutput(outputId = 'map', height = 600)),
column(12,
dataTableOutput('my_table'))))
Note: I was not able to test it due to lack of reproducible example but I hope this should work in your case.
Resolved with the help of RCommunity worldwide.
# User interface
ui <- fluidPage(theme = shinytheme("united"),
titlePanel(HTML("<h1><center><font size=14> Crimes in Washington, DC (2017) </font></center></h1>")),
fluidRow(column(4, align="center",
selectInput("offenceInput", "Type of Offence",
choices = sort(unique(incidents$Offense)),
selected = sort(unique(incidents$Offense)),
multiple = TRUE),
selectInput("methodInput", "Method of Offence",
choices = sort(unique(incidents$Method)),
selected = sort(unique(incidents$Method)),
multiple = TRUE),
selectInput("shiftInput", "Police Shift",
choices = sort(unique(incidents$Shift)),
selected = sort(unique(incidents$Shift)),
multiple = TRUE),
selectInput('background', 'Background',
choices = providers,
multiple = FALSE,
selected = 'Stamen.TonerLite'),
dateRangeInput('daterangeInput',
label = 'Date',
start = as.Date('2017-01-01') , end = as.Date('2017-12-31')
),
br(),
plotOutput("bar")
),
column(8,
leafletOutput(outputId = 'map', height = 600, width = 800),
dataTableOutput('my_table')
)
))
This gives the following layout. It is messy, but the structure is what I really wanted. Will improved small tweaks.

Resources