What am I doing wrong here?
Main code:
<code>library(shiny)
ui <- bslib::page_navbar(
title = 'Layout App',
nav_panel(
title = "First",
fluidRow(
class = 'first_page_grid',
nameUI('one')
)
)
)
server <- function(input, output, session) {
nameServer('one')
}
shinyApp(ui, server)
</code>
<code>library(shiny)
ui <- bslib::page_navbar(
title = 'Layout App',
nav_panel(
title = "First",
fluidRow(
class = 'first_page_grid',
nameUI('one')
)
)
)
server <- function(input, output, session) {
nameServer('one')
}
shinyApp(ui, server)
</code>
library(shiny)
ui <- bslib::page_navbar(
title = 'Layout App',
nav_panel(
title = "First",
fluidRow(
class = 'first_page_grid',
nameUI('one')
)
)
)
server <- function(input, output, session) {
nameServer('one')
}
shinyApp(ui, server)
The module code:
<code>nameUI <- function(id) {
ns <- NS(id)
tagList(
tags$img(
src = paste0('img/Word1/', list.files(path = 'www/img/Word1')[1]),
style = "width:50%; height:50%; object-fit:cover;object-position: top;
cursor:pointer;",
onclick = sprintf("Shiny.setInputValue('%s_img_click', '%s')",
ns('img_click'), list.files(path = 'www/img/Word1')[1])
)
)
}
nameServer <- function(id) {
moduleServer(
id,
function(input, output, session) {
observeEvent(input$img_click, {
req(input$img_click) # Garante que o valor não está vazio
showModal(modalDialog(
title = "Clicked Image",
paste("You clicked:", input$img_click),
easyClose = TRUE
))
})
}
)
}
</code>
<code>nameUI <- function(id) {
ns <- NS(id)
tagList(
tags$img(
src = paste0('img/Word1/', list.files(path = 'www/img/Word1')[1]),
style = "width:50%; height:50%; object-fit:cover;object-position: top;
cursor:pointer;",
onclick = sprintf("Shiny.setInputValue('%s_img_click', '%s')",
ns('img_click'), list.files(path = 'www/img/Word1')[1])
)
)
}
nameServer <- function(id) {
moduleServer(
id,
function(input, output, session) {
observeEvent(input$img_click, {
req(input$img_click) # Garante que o valor não está vazio
showModal(modalDialog(
title = "Clicked Image",
paste("You clicked:", input$img_click),
easyClose = TRUE
))
})
}
)
}
</code>
nameUI <- function(id) {
ns <- NS(id)
tagList(
tags$img(
src = paste0('img/Word1/', list.files(path = 'www/img/Word1')[1]),
style = "width:50%; height:50%; object-fit:cover;object-position: top;
cursor:pointer;",
onclick = sprintf("Shiny.setInputValue('%s_img_click', '%s')",
ns('img_click'), list.files(path = 'www/img/Word1')[1])
)
)
}
nameServer <- function(id) {
moduleServer(
id,
function(input, output, session) {
observeEvent(input$img_click, {
req(input$img_click) # Garante que o valor não está vazio
showModal(modalDialog(
title = "Clicked Image",
paste("You clicked:", input$img_click),
easyClose = TRUE
))
})
}
)
}
The idea: The user clicks on the image and the image shows up as a modal on the screen.
I don’t know how to use javascript properly, and I believe that this is the reason of the problem.
How do to this?