How to generate dynamic html in rmarkdown

Can rmarkdown only generate static html. I have a lot of images in one part of the document. I want to be able to switch between left and right like in unusual html, but when generating the html I can only show one image or all of them, there is no way to switch between images. And I know very little about javascript. I only know that DT can be used to do this interactively. Is there any R package or other way similar to DT to switch?

I'm trying to understand what you are asking for; im thinking you might be asking about horizontal scrolling ? or a carousel ?

I'm very sorry for not being descriptive.
Let's say I have 5 images and I want to be able to display the images like DT displays a table

a shiny tabset is similar, although it would have the buttons above rather than below the tabs.

library(shiny)

ui <- fluidPage(
  sliderInput("num_tabs",
              "Number of Tabs",
              min=1,
              max=5,
              value=3,
              step=1L),
  uiOutput("dyntabset")
)

my_seq <- 1:3

server <- function(input, output, session) {
  my_seq <- reactive({
    seq_len(req(input$num_tabs))
  }  )
  
  observeEvent(my_seq(),
               {
                 my_seq <- req(my_seq())
                 lapply(my_seq,\(i){
                   output[[paste0("plot",i)]] <- renderPlot({
                     myx<-1:10
                     myy<-(1:10)^i
                     plot(x=myx,y=myy)
                   })
                 }) 
               })
  
  
  output$dyntabset <- renderUI({
    my_seq <- req(my_seq())
    myTabs <- lapply(my_seq,\(i){
      do.call(tabPanel,args=list(as.character(i),
                                 plotOutput(paste0("plot",i))))
    })
                do.call(what = tabsetPanel, ,
                        args = myTabs)
                
  })
}

shinyApp(ui, server)

Thank you very much for your reply.!
But I know only a little about javascript . the point is that I don't know to link rmarkdown and javascript, if I write a piece of javascript function I don't know where to put it. Because my R has to detect the image position to insert the image.
And I've tried nesting javascript inside R before which is a pain, and I need to set the state of each image and speak the state change based on the button.

Thank you for your reply!
In R shiny. I was able to design ui and functions autonomously. But shinyapp can only be used locally by me. I can't share the html to others. Also, I previously deployed shiny in ubuntu others were not able to view the webpage. Since I don't know javascript, I was wondering if there is any R package that can do this, even if he looks simple.
I asked the question once, but then gave it up
How to let other people use shinyapp via web page - shiny - Posit Community (rstudio.com)

sorry, I missed the part where you wanted static HTML

Here is a section on tabsets in Rmarkdown/HTML

OK, thanks for the reply!
But I realized that this can only be achieved by designing the section headings myself. If I have more than 5 images, then this would be painful. It would be better to have a button for next and previous like DT, and easy to encapsulate like a function!
If there is no such function or R package . I think this would be the optimal solution

Here I made a proof of concept, that pure html/css can be used to create this kind of interaction

<html>
  <<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <<style type="text/css" media="all">
      div:not(.toggle) {
  display: block;
}
div.toggle {
  display: none;
}
div.toggle:target {
  display: block;
}
    </style>
  </head>
  <body>
    
    <div>
  <p>This is a regular div that is always shown</p>
  <a href = "#div1">Press to Begin</a>
</div>



<div class="toggle" id="div1">
  <p>This is div 1</p>
  <del>Previous</del>
  <span>1/5</span>
  <a href="#div2">Next</a>
</div>

<div class="toggle" id="div2">
  <p>This is div 2</p>
  <a href="#div1">Previous</a>
    <span>2/5</span>
  <a href="#div3">Next</a>
</div>

<div class="toggle" id="div3">
  <p>This is div 3</p>
  <a href="#div2">Previous</a>
    <span>3/5</span>
  <a href="#div4">Next</a>
</div>

<div class="toggle" id="div4">
  <p>This is div 4</p>
  <a href="#div3">Previous</a>
    <span>4/5</span>
  <a href="#div5">Next</a>
</div>

<div class="toggle" id="div5">
  <p>This is div 5</p>
  <a href="#div4">Previous</a>
    <span>5/5</span>
    <del>Next/del>
</div>
  </body>
</html>

For what it worth, Quarto has integrated now the Lighbox feature to create a gallery of images:

This could help in such situation maybe.

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.