Confusing Mistakes: The Package Plotly is not compatible with presentation html files in tabPanles

When I try to pagicate, one of the pages shows two html files that I exported with rmarkdown, which are displayed separately in the left and right columns of the same page, and I find a confusing phenomenon, which is that the left one does not display and the right one is displayed. Then I tested it, replaced the display with HTML ('

Test HTML

'), and the left and right columns were displayed again, and my shiny program looked like this, and the test .html was the default content of rmarkdown.

library(shiny)
library(plotly)
library(tidyverse)
library(ggsci)
library(rsconnect)

ID = list.files("./files/Participants")
Tn = list.files("./files/Task/")
df_score = list.files("./files/Participants", recursive = T, full.names = T, pattern = "txt") %>% 
  lapply(read_tsv) %>% 
  imap(function(df, i){mutate(df, Participants = rep(ID, each = length(ID))[i], Task = rep(Tn, 3)[i])}) %>% 
  bind_rows() %>% 
  rowwise() %>% 
  mutate(Score = sum(c_across(matches("[\u4E00-\u9FFF]"))))
df_all = df_score %>% 
  group_by(Participants) %>% 
  summarise(Score = sum(Score)) %>% 
  ungroup() %>% 
  mutate(Task = "All")
df_data = bind_rows(df_score, df_all)


ui = fluidPage(
  titlePanel("MITUS成员半月练习得分"), 
  tabsetPanel(
    tabPanel("dashboard", 
             sidebarLayout(position = "left",
                           sidebarPanel(
                             selectInput(
                               inputId = "main_control",
                               label = "Options",
                               choices = c("Preview", "By Task", "By Participants")),
                             uiOutput(outputId = "secondary_control")),
                           mainPanel(plotOutput("Bar_Score"))
             )
    ),
    tabPanel("temp"), 
    tabPanel("code",
             fluidRow(
               selectInput("task_code", "Which Task?", choices = c("", Tn), selected = "")
             ), 
             fluidRow(
               column(
                 width = 6,
                 htmlOutput("Describtion")
               ),
               column(
                 width = 6,
                 htmlOutput("Resolution")
               )
             )
    )
  )
)


server = function(input, output) {
  
  output$secondary_control = renderUI({
    render_control_ui(input$main_control)
  })
  
  render_control_ui = function(option) {
    
    switch(
      option,
      "Preview" = NULL,
      "By Task" = selectInput("task", "Which Task?", choices = unique(df_data[["Task"]]), selected = "T1"),
      "By Participants" = div(
        selectInput("member", "Which Member?", choices = ID, selected = "GouGe"), 
        selectInput("terms", "Details?", choices = c("No, thanks", Tn), selected = "No, thanks")
      )
    )
  }
  
  optioned = reactive({
    switch(
      input$main_control,
      "Preview" = df_data %>% 
        filter(Task != "All") %>% 
        ggplot() +
        geom_col(aes(x = Task,y = Score, fill = Participants),
                 position = position_dodge(0.8), width = 0.6) +
        scale_fill_lancet() +
        theme_bw() +
        labs(title = "Outlook of Participants' Grades") +
        theme(plot.title = element_text(hjust = 0.5, face = "bold")) +
        ylim(c(0, 5)), 
      
      "By Task" = df_data %>% 
        filter(Task == input$task) %>% 
        ggplot() +
        geom_col(aes(x = Participants,y = Score, fill = Participants),
                 position = position_dodge(0.8), width = 0.6) +
        scale_fill_lancet() +
        theme_bw() +
        labs(title = input$task) +
        theme(plot.title = element_text(hjust = 0.5, face = "bold")), 
      
      "By Participants" = {
        if(input$terms == "No, thanks"){
          df_data %>% 
            filter(Participants == input$member) %>% 
            filter(Task != "All") %>% 
            ggplot() +
            geom_col(aes(x = Task,y = Score, fill = Task),
                     position = position_dodge(0.8), width = 0.6) +
            scale_fill_lancet() +
            theme_bw() +
            labs(title = input$member) +
            theme(plot.title = element_text(hjust = 0.5, face = "bold")) +
            ylim(c(0, 5))
        }else{
          df_data %>% 
            filter(Participants == input$member) %>% 
            filter(Task == input$terms) %>% 
            select(Task, 可运行:优化) %>% 
            pivot_longer(-Task, names_to = "Terms", values_to = "Score") %>% 
            ggplot() +
            geom_col(aes(x = Terms,y = Score, fill = Terms),
                     position = position_dodge(0.8), width = 0.6) +
            scale_fill_lancet() +
            theme_bw() +
            labs(title = input$terms) +
            theme(plot.title = element_text(hjust = 0.5, face = "bold"),
                  legend.position = "bottom") +
            ylim(c(0, 2))
        }
      }
    )
  })
  output$Bar_Score = renderPlot({optioned()})
  
  output$Describtion = renderUI({
    req(input$task_code)
    includeHTML("./test.html")
  })
  output$Resolution = renderUI({
    req(input$task_code)
    includeHTML("./test1.html")
  })
}

shinyApp(ui, server)

Before, I used to use renderplotly and the like, but then I changed it to renderplot, and now the html files on both sides can be displayed normally. I hope this reported bug gets your attention.

This topic was automatically closed 54 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.