Comments (5)
There are two issues that are causing this problem. First, your ids are already used in other places; you might renaming the modals to "light_red_modal" for example. That will allow the modal to show up, but the display is still not quite right.
The second thing is to move the bs_modal calls from the sidebar into the body. Then everything should work as expected. Fully fixed code example below:
library(shiny)
library(shinydashboard)
library(tidyverse)
library(DT)
library(shinyTree)
library(bsplus)
# SET UP EXAMPLE STRUCTURES
#creates random vector of 5 doubles between 0 and 1.
rand_5 <- function(){
return(sample.int(100,
size=5,
replace=TRUE)/100
)
}
#example df for app
df <- tibble(entrez_gene_id=c(12,35,9,10,500),
gene_symbol=c("A1BG", "A2M", "A2MP1", "NAT1", "NAT2"),
light_blue=rand_5(),
medium_blue=rand_5(),
dark_blue=rand_5(),
light_red=rand_5(),
dark_red=rand_5()
)
#list to be used as shinytree
tree <- structure(list(reds = structure(list(light_red = "",
dark_red=""),
stdisabled=T,
stopened=T),
blues = structure(list(light_blue="",
medium_blue="",
dark_blue=""),
stdisabled=T,
stopened=T)
)
)
#modal information
modal_info <- c("light_blue/HELLO LIGHT BLUE",
"medium_blue/HELLO MEDIUM BLUE",
"dark_blue/HELLO DARK BLUE",
"light_red/HELLO LIGHT RED",
"dark_red/HELLO DARK RED")
ui <- dashboardPage(skin="red",
dashboardHeader(
title = "testing",
titleWidth=300
),
dashboardSidebar(
width=300,
shinyTree("tree", checkbox=TRUE, search=TRUE, theme="default-dark"),
uiOutput("selected_analyses")
),
dashboardBody(
fluidPage(
DT::dataTableOutput("df"),
###Move modal creation to here
lapply(1:length(modal_info), function(i) {
this_id <- modal_info[i] %>% str_replace("/.*", "")
this_body <- modal_info[i] %>% str_replace(".*/", "")
###ADD _modal here
bs_modal(id = paste0(this_id,"_modal"), title = this_id, body = this_body)
})
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$tree <- renderTree({ tree })
output$selected_analyses <- renderUI({
selected <- input$tree %>% get_selected %>% unlist %>% setdiff(names(tree))
if(length(selected)){
print(selected)
lapply(1:length(selected), function(i) {
fluidRow(numericInput(inputId=selected[i], label=selected[i], value=1, min=0, max=1, step=0.1) %>%
shinyInput_label_embed(
shiny_iconlink() %>%
###ADD _modal here
bs_attach_modal(id_modal = paste0(selected[i],"_modal"))
)
)
})
}
})
output$df = DT::renderDataTable({
selected <- input$tree %>% get_selected %>% unlist %>% setdiff(names(tree))
if(length(selected)){
df <- df %>% select(c("entrez_gene_id", "gene_symbol", one_of(selected)))
datatable(df)
} else {
datatable(df[,1:2])
}
})
}
# Run the application
shinyApp(ui = ui, server = server)
from bsplus.
Yep this works perfectly. Thank you!
from bsplus.
It would be great if you would provide a reproducible example.
Also, for me, whenever something goes wrong, many times it is because I have created HTML elements with duplicate ID's.
from bsplus.
Thanks for the quick response. I create the IDs through a loop so I can't see where I might make multiple. Here is a trimmed down example. You should be able to run this and replicate the behavior. My goal is to be able to pick the contents of the modal with an HTML file, but for now im just trying to get text in there which corresponds to the created input.
library(shiny)
library(shinydashboard)
library(tidyverse)
library(DT)
library(shinyTree)
library(bsplus)
# SET UP EXAMPLE STRUCTURES
#creates random vector of 5 doubles between 0 and 1.
rand_5 <- function(){
return(sample.int(100,
size=5,
replace=TRUE)/100
)
}
#example df for app
df <- tibble(entrez_gene_id=c(12,35,9,10,500),
gene_symbol=c("A1BG", "A2M", "A2MP1", "NAT1", "NAT2"),
light_blue=rand_5(),
medium_blue=rand_5(),
dark_blue=rand_5(),
light_red=rand_5(),
dark_red=rand_5()
)
#list to be used as shinytree
tree <- structure(list(reds = structure(list(light_red = "",
dark_red=""),
stdisabled=T,
stopened=T),
blues = structure(list(light_blue="",
medium_blue="",
dark_blue=""),
stdisabled=T,
stopened=T)
)
)
#modal information
modal_info <- c("light_blue/HELLO LIGHT BLUE",
"medium_blue/HELLO MEDIUM BLUE",
"dark_blue/HELLO DARK BLUE",
"light_red/HELLO LIGHT RED",
"dark_red/HELLO DARK RED")
ui <- dashboardPage(skin="red",
dashboardHeader(
title = "testing",
titleWidth=300
),
dashboardSidebar(
width=300,
shinyTree("tree", checkbox=TRUE, search=TRUE, theme="default-dark"),
uiOutput("selected_analyses"),
lapply(1:length(modal_info), function(i) {
this_id <- modal_info[i] %>% str_replace("/.*", "")
this_body <- modal_info[i] %>% str_replace(".*/", "")
bs_modal(id = this_id, title = this_id, body = this_body)
})
),
dashboardBody(
fluidPage(
DT::dataTableOutput("df")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$tree <- renderTree({ tree })
output$selected_analyses <- renderUI({
selected <- input$tree %>% get_selected %>% unlist %>% setdiff(names(tree))
if(length(selected)){
lapply(1:length(selected), function(i) {
fluidRow(numericInput(inputId=selected[i], label=selected[i], value=1, min=0, max=1, step=0.1) %>%
shinyInput_label_embed(
shiny_iconlink() %>%
bs_attach_modal(id_modal = selected[i])
)
)
})
}
})
output$df = DT::renderDataTable({
selected <- input$tree %>% get_selected %>% unlist %>% setdiff(names(tree))
if(length(selected)){
df <- df %>% select(c("entrez_gene_id", "gene_symbol", one_of(selected)))
datatable(df)
} else {
datatable(df[,1:2])
}
})
}
# Run the application
shinyApp(ui = ui, server = server)
from bsplus.
Thanks @bellma-lilly! I am very relieved that this example is working!
from bsplus.
Related Issues (20)
- reactive bs_modal
- Limit to number of bstooltip that will show up?
- How to create bs_modal() in a loop in rmarkdown? HOT 1
- Stop carousel autoplay using Shiny and JavaScript
- `bsplus` only works for `html_document` but not `bookdown`?
- Error in .tag_validate(tag, name = "div", class = "form-group shiny-input-container")
- Usage of bs_embed_popover inside module
- Is this package still supported? HOT 1
- Release bsplus 0.1.3
- fix pkgdown
- Compatability with rstudio/bslib bootstrap version 4 or 5? HOT 3
- Compatibility with Bootstrap 5
- bsTooltip does not allow special characters
- fix CRAN issues
- Release bsplus 0.1.4 HOT 1
- Release bsplus 0.1.4
- Different tooltip behavior with htmlOutput()/renderUI()
- Customize colors
- Allow multiple panels to be open at one time HOT 3
- bsplus Package in Quarto (RStudio): Modals Not Opening
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bsplus.