Insert the bs_embed_popover function in my shiny - r

Friends, could you help me insert a bs_embed_popover in my shiny. I would like to add an icon similar to the image below to be able to make a descriptive text.
I would like to insert for the first radioButton.
library(shinyBS)
library(shiny)
ui <- fluidPage(
titlePanel("Old Faithful Geyser Data"),
sidebarLayout(
sidebarPanel(
radioButtons("filter1", h3("Select properties"),
choices = list("All properties" = 1,
"Exclude properties" = 2),
selected = 1),
radioButtons("filter2", h3("Select farms"),
choices = list("All farms" = 1,
"Exclude farms" = 2),
selected = 1),
sliderInput("bins",
"Number of bins:",
min = 1,
max = 20,
value = 30)
),
mainPanel(
plotOutput("distPlot")
)
)
)
server <- function(input, output) {
output$distPlot <- renderPlot({
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
}
shinyApp(ui = ui, server = server)
Example
Thank you very much!

radioButtons(
"filter1",
tagList(
tags$span("Select properties", style = "font-size: 24px; font-weight: normal;"),
tags$span(icon("info-circle"), id = "icon", style = "color: blue;")
),
choices = list("All properties" = 1,
"Exclude properties" = 2),
selected = 1
),
bsPopover("icon", "TITLE", "CONTENT", placement = "right"),
To have a popover for the options of the radio buttons, do:
radioButtons(
"filter1",
h3("Select properties"),
choiceValues = c(1, 2),
choiceNames = list(
tagList(
tags$span("All properties"),
tags$span(icon("info-circle"), id = "icon1", style = "color: blue;")
),
tagList(
tags$span("Exclude properties"),
tags$span(icon("info-circle"), id = "icon2", style = "color: blue;")
)
),
selected = 1
),
bsPopover("icon1", "TITLE1", "CONTENT1", placement = "right"),
bsPopover("icon2", "TITLE2", "CONTENT2", placement = "right"),

Related

Adjust plotly output height to box with dynamic height in shiny dashboard

In the shiny app below I have a box which height depends on the number of shiny widgets it includes and a plot. I would like the box height to somehow saved every time it changes and be passed to the plot in order to have the same height always.
library(shiny)
library(plotly)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
# Copy the line below to make a set of radio buttons
radioButtons("radio1", label = h3("Radio buttons"),
choices = list("Choice 1" = 1, "Choice 2" = 2),
selected = 1)
),
dashboardBody(
fluidRow(
column(4,
box(
# Copy the line below to make a set of radio buttons
radioButtons("radio2", label = h3("Radio buttons"),
choices = list("Choice 1" = 1, "Choice 2" = 2, "Choice 3" = 3),
selected = 1),
uiOutput("rd3")
)),
plotlyOutput("t2")
)
)
)
server <- function(input, output, session) {
output$rd3<-renderUI({
if(input$radio1==1){
return(NULL)
}
else{
radioButtons("radio3", label = h3("Radio buttons"),
choices = list("Choice 1" = 1, "Choice 2" = 2, "Choice 3" = 3),
selected = 1)
}
})
output$t2<-renderPlotly(
fig <- plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length)
)
}
shinyApp(ui, server)
The following works based on spsComps::heightMatcher.
However, I needed to trigger a resize event via shinyjs to avoid the plot height getting out of sync after a few clicks, which I think should not be necessary (also makes it quite slow).
library(shiny)
library(plotly)
library(shinydashboard)
library(spsComps)
library(shinyjs)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(# Copy the line below to make a set of radio buttons
radioButtons(
"radio1",
label = h3("Radio buttons"),
choices = list("Choice 1" = 1, "Choice 2" = 2),
selected = 1
)),
dashboardBody(
useShinyjs(),
fluidRow(
column(4,
box(
id = "box_1",
# Copy the line below to make a set of radio buttons
radioButtons(
"radio2",
label = h3("Radio buttons"),
choices = list(
"Choice 1" = 1,
"Choice 2" = 2,
"Choice 3" = 3
),
selected = 1
),
uiOutput("rd3")
)),
box(id = "box_2", plotlyOutput("t2", height = "100%")),
spsComps::heightMatcher("box_2", "box_1")
)
)
)
server <- function(input, output, session) {
observeEvent(input$radio1, {
shinyjs::runjs("$(window).trigger('resize');")
})
output$rd3 <- renderUI({
if (input$radio1 == 1) {
return(NULL)
} else {
radioButtons(
"radio3",
label = h3("Radio buttons"),
choices = list(
"Choice 1" = 1,
"Choice 2" = 2,
"Choice 3" = 3
),
selected = 1
)
}
})
output$t2 <- renderPlotly({fig <-
plot_ly(
data = iris,
x = ~ Sepal.Length,
y = ~ Petal.Length
)})
}
shinyApp(ui, server)

Space between 2 widgets in R Shiny

Can someone please explain me the reason for having a big whitespace between following?
server = function(input, output){
# server code
}
ui = fluidPage(
fluidRow(
column(8, offset = 0, style='padding:0px;', # Sidebar panel
sidebarPanel(useShinyjs(),
dateRangeInput('dateRange',
label = 'Filter crimes by date',
start = as.Date('2019-01-01') , end = as.Date('2021-06-01')),
selectInput("var", label = "1. Select the quantitative Variable",
choices = c("place_of_death"=3,"Month Name"=11, "cause_of_death"=8), selected = 8),
radioButtons( "dist", "Enable or disable Grouping:",
c("Enable" = "enable",
"Disable" = "disable" ), inline=T),
selectInput("var2", label = "1. Select the quantitative Variable",
choices = c("cause_of_death"=8, "year"=7), selected = 7),
radioButtons( "CauseOfDeathRad", "Enable or disable Grouping:",
c("Covid" = "covid",
"Non-Covid" = "nonCovid" ,
"Both" = "both"), inline=T),
radioButtons( "DeathonYearRad", "Enable or disable Grouping:",
c(
"2020" = "2020" ,
"2021" = "2021",
"All" = "All"), inline=T)
)),
column(2, offset = 0, style='padding:0px;', wellPanel(p("Column width 2"))),
column(2, offset = 0, style='padding:0px;', wellPanel(p("Column width 2")))
)
)
shinyApp(ui = ui, server = server)
I need my dashboard to be equally divided among different plots. But this seems really hard to be done.
Appreciate if someone could help
PS.
When column(8,...) is set to column(3...)
My suggestion is to use the fluidRow() and column() in the mainPanel() to display the plots. Widgets for input can be kept in sidebarPanel(). Try this
server = function(input, output){
# server code
}
ui = fluidPage(
useShinyjs(),
sidebarLayout(
sidebarPanel(
dateRangeInput('dateRange',
label = 'Filter crimes by date',
start = as.Date('2019-01-01') , end = as.Date('2021-06-01')),
selectInput("var", label = "1. Select the quantitative Variable",
choices = c("place_of_death"=3,"Month Name"=11, "cause_of_death"=8), selected = 8),
radioButtons( "dist", "Enable or disable Grouping:",
c("Enable" = "enable",
"Disable" = "disable" ), inline=T),
selectInput("var2", label = "1. Select the quantitative Variable",
choices = c("cause_of_death"=8, "year"=7), selected = 7),
radioButtons( "CauseOfDeathRad", "Enable or disable Grouping:",
c("Covid" = "covid",
"Non-Covid" = "nonCovid" ,
"Both" = "both"), inline=T),
radioButtons( "DeathonYearRad", "Enable or disable Grouping:",
c(
"2020" = "2020" ,
"2021" = "2021",
"All" = "All"), inline=T)
),
mainPanel(
fluidRow(
column(5, offset = 0, style='padding:0px;', wellPanel(p("Column width 5"))),
column(5, offset = 0, style='padding:0px;', wellPanel(p("Column width 5")))
)
)
)
)
shinyApp(ui = ui, server = server)

Insert bspopover in Shiny

I would like to insert a bspopover next to the text: "Shapefile Import". For the Filter options I was able to insert as you can see in the code below, however for fileImput no. The executable code is below.
can anybody help me?
Thank you!
library(shinyBS)
library(shiny)
popoverTempate <-
'<div class="popover popover-lg" role="tooltip"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>'
DES_filter1<-paste("Text text text text text text.", sep = "<br>")
ui <- fluidPage(
tags$head(
tags$style(HTML(".popover.popover-lg {width: 500px; max-width: 500px;}"))
),
titlePanel("Old Faithful Geyser Data"),
sidebarLayout(
sidebarPanel(
fileInput("shp", h3("Shapefile import"), multiple = TRUE, accept = c('.shp', '.dbf','.sbn', '.sbx', '.shx', '.prj')),
radioButtons(
"filter1",
h3("Select properties"),
choiceValues = c(1, 2),
choiceNames = list(
tagList(
tags$span("All properties"),
tags$span(icon("info-circle"), id = "icon1", style = "color: blue;")
),
tagList(
tags$span("Exclude properties"),
tags$span(icon("info-circle"), id = "icon2", style = "color: blue;")
)
),
selected = 1
),
bsPopover("icon1", "TITLE1", DES_filter1, placement = "right",
options = list(template = popoverTempate)),
bsPopover("icon2", "TITLE2", "CONTENT2", placement = "right"),
radioButtons("filter2", h3("Select"),
choices = list("All" = 1,
"Exclude" = 2),
selected = 1),
),
mainPanel(
)
)
)
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)
You can add the icon in the fileInput title:
sidebarPanel(
fileInput("shp",
h3(
span("Shapefile import"),
span(icon("info-circle"), id = "icon3", style = "color: blue")
),
multiple = TRUE,
accept = c('.shp', '.dbf','.sbn', '.sbx', '.shx', '.prj')
),
bsPopover("icon3", "TITLE3", "CONTENT3", placement = "right"),
...

Insert warning message from selectInput option

Friends, could you help me to insert a warning message if an option is selected in selecInput. In my case, I would like it to be the case if the option "Exclude farms" is selected, a message like: Change filter options selected above. The executable code is below:
library(shinyBS)
library(shiny)
popoverTempate <-
'<div class="popover popover-lg" role="tooltip"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>'
DES_filter1<-paste(".........", sep = "<br>")
ui <- fluidPage(
tags$head(
tags$style(HTML(".popover.popover-lg {width: 500px; max-width: 500px;}"))
),
titlePanel("Old Faithful Geyser Data"),
sidebarLayout(
sidebarPanel(
radioButtons(
"filter1",
h3("Select properties"),
choiceValues = c(1, 2),
choiceNames = list(
tagList(
tags$span("All properties"),
tags$span(icon("info-circle"), id = "icon1", style = "color: blue;")
),
tagList(
tags$span("Exclude properties"),
tags$span(icon("info-circle"), id = "icon2", style = "color: blue;")
)
),
selected = 1
),
bsPopover("icon1", "TITLE1", DES_filter1, placement = "right",
options = list(template = popoverTempate)),
bsPopover("icon2", "TITLE2", "CONTENT2", placement = "right"),
selectInput("filter2", h3("Select farms"),
choices = list("All farms" = 1,
"Exclude farms" = 2),
selected = 1),
),
mainPanel(
)
)
)
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)
If you are open to using another package here is a shinyWidgets solution with a 'sendSweetAlert':
library(shinyWidgets)
library(shiny)
ui <- fluidPage(
titlePanel("Old Faithful Geyser Data"),
sidebarLayout(
sidebarPanel(
radioButtons(
"filter1",
h3("Select properties"),
choiceValues = c(1, 2),
choiceNames = list(
tagList(
tags$span("All properties"),
tags$span(icon("info-circle"), id = "icon1", style = "color: blue;")
),
tagList(
tags$span("Exclude properties"),
tags$span(icon("info-circle"), id = "icon2", style = "color: blue;")
)
),
selected = 1
),
selectInput("filter2", h3("Select farms"),
choices = list("All farms" = 1,
"Exclude farms" = 2),
selected = 1),
),
mainPanel(
)
)
)
server <- function(input, output, session) {
observe({
if(input$filter2 == 2){
sendSweetAlert(
session = session,
title = "Warning!",
text = "Change filter options selected above",
type = "warning"
)
}
})
}
shinyApp(ui = ui, server = server)
All is needed is to observe the selectInput value and when the input is on "Exclude farms" which has a value of 2 a warning message is sent.

Adjusting location of Main panel in Shiny

I have created the following UI using R shiny. The script is as follows.
The first part deals with the sidebar layout.
ui <- fluidPage(
titlePanel("Graphingtool"),
h3("DB"),
hr(),
fluidRow(
column(12,
fluidRow(
column(3,
fileInput("file1", 'DB',
multiple = TRUE,
accept = c("xlsx/xls",".xls",".xlsx"))),# We have added the formats here- will load excel alone- in case csv/txt needed amend here
column(5,
column(4,downloadButton(outputId = "Downloaddata", label = "Downloader"))
)
),
fluidRow(
column(3,
textInput(inputId = 'T',label = 'T'),
textInput(inputId = 'C',label = 'C'),
textInput(inputId = "P", label = "P"),
column(2, offset = 2,
actionButton(inputId = "CLS", label = "CLS"))
),
column(5,
textInput(inputId = "P", label = "P"),
textInput(inputId = "Y", label = "Y"),
numericInput(inputId = "Numberinput", label = "Ninput", min = -1000000000, max = 1000000000, value = 0,step = 1)
)),
fluidRow(
column(3,
radioButtons("dist", "Vertical Axis Scale",
c("Linear" = "Linear Reg",
"Log" = "Log reg"))),
column(5,
radioButtons("dist", "Horizontal Axis Scale",
c("Linear" = "Linear reg",
"Log" = "Log reg")))
),
fluidRow(
column(5,
sliderInput(inputId = "Scale", label = "Scale", min = 0, max = 100,
step = 2.5, value = 1))) ) )
Here we create the main panel
,mainPanel(
tabsetPanel(
tabPanel("Plot", plotOutput("plot")),
tabPanel("Table", tableOutput("table"))
)))
server<-function(input, output){reactive({})}
shinyApp(ui, server)
I Have created the main panel. However, the Panel with two tabs is opening under the sidebar panel and not on the right hand side of the panel.
The script works but is it possible to open the main panel on the right of the sidebar panel. I request someone to guide me here.
Take a look on this if this okay or not for you..
library(shiny)
ui <- fluidPage(
titlePanel("Graphingtool"),
h3("DB"),
hr(),
sidebarLayout(
sidebarPanel(
fluidRow(
column(5,
ailgn="center",
fileInput("file1", 'DB',
multiple = TRUE,
accept = c("xlsx/xls",".xls",".xlsx"))),# We have added the formats here- will load excel alone- in case csv/txt needed amend here
column(5,
ailgn="center",
HTML('<br/>'),
column(4,downloadButton(outputId = "Downloaddata", label = "Downloader"))
)
),
fluidRow(
column(5,
ailgn="center",
textInput(inputId = 'T',label = 'T'),
textInput(inputId = 'C',label = 'C'),
textInput(inputId = "P", label = "P"),
column(2, offset = 2,
ailgn="center",
actionButton(inputId = "CLS", label = "CLS"))
),
column(5,
ailgn="center",
textInput(inputId = "P", label = "P"),
textInput(inputId = "Y", label = "Y"),
numericInput(inputId = "Numberinput", label = "Ninput", min = -1000000000, max = 1000000000, value = 0,step = 1)
)),
HTML('<br/>'),
fluidRow(
column(5,
ailgn="center",
radioButtons("dist", "Vertical Axis Scale",
c("Linear" = "Linear Reg",
"Log" = "Log reg"))),
column(5,
ailgn="center",
radioButtons("dist", "Horizontal Axis Scale",
c("Linear" = "Linear reg",
"Log" = "Log reg")))
),
fluidRow(
column(5,
ailgn="center",
sliderInput(inputId = "Scale", label = "Scale", min = 0, max = 100,
step = 2.5, value = 1)))
)
,mainPanel(
tabsetPanel(
tabPanel("Plot", plotOutput("plot")),
tabPanel("Table", tableOutput("table"))
)))
)
server<-function(input, output){reactive({})}
shinyApp(ui, server)
You can tweak the size by adjusting column

Resources