R 单击一个超链接并返回原始web,它将再次连接或界面模糊

R 单击一个超链接并返回原始web,它将再次连接或界面模糊,r,shiny,hyperlink,R,Shiny,Hyperlink,在我闪亮的应用程序web中有几个链接 当我单击超链接返回web时,它总是重新加载或界面模糊。 library(shiny) library(dplyr) library(tidyr) library(ggplot2) library(gridExtra) mean_data <- data.frame( Name = c(paste0("Group_", LETTERS[1:20])), matx

在我闪亮的应用程序web中有几个链接

当我单击超链接返回web时,它总是重新加载或界面模糊。

library(shiny)
    library(dplyr)
    library(tidyr)
    library(ggplot2)
    library(gridExtra)
    
    mean_data <- data.frame(
      Name = c(paste0("Group_", LETTERS[1:20])),
      matx <- matrix(sample(1:1000, 1000, replace = T), nrow = 20)
    )
    names(mean_data)[-1] <- c(paste0("Gene_", 1:50))
    
    sd_data <- data.frame(
      Name = c(paste0("Group_", LETTERS[1:20])),
      matx <- matrix(runif(1000, 5, 10), nrow = 20)
    )
    names(sd_data)[-1] <- c(paste0("Gene_", 1:50))
    
    
    ###
    ui <- fluidPage(
      
      pageWithSidebar(
        headerPanel("123"),
        sidebarPanel(
          selectInput(
            "selectGeneSymbol",
            "123:",
            choices = colnames(mean_data)[-1],
            multiple =F,
            width = 400,
            selected = 1
          ),
          
          actionButton(inputId = "plot1", label = "FPKM"),
          tags$h6(tags$a(href="https://www.ncbi.nlm.nih.gov/", "link",target = "_blank"))
        ),
        mainPanel(
          plotOutput("plot")
          #uiOutput("all")
        )
      )
      
    )
    
    server <- function(input, output, session) {
      
      ## put sd into mean_data
      plotdata <- eventReactive(input$plot1, { 
        df <- mean_data %>% mutate(sd = sd_data[,input$selectGeneSymbol])
      })
      
      p1 <- eventReactive(input$plot1, {
        ggplot(data = plotdata(), aes(x = Name, y = .data[[input$selectGeneSymbol]], fill=Name,
                                      ymin = .data[[input$selectGeneSymbol]] - sd, ymax = .data[[input$selectGeneSymbol]] + sd )) +
          geom_bar(stat = "identity", position = position_dodge(0.9), width = 0.9) +
          # geom_errorbar(aes(ymin = plotdata()[,input$selectGeneSymbol] - sddata()[,input$selectGeneSymbol], ymax = plotdata()[,input$selectGeneSymbol] + sddata()[,input$selectGeneSymbol]), width = .2, position = position_dodge(0.9)) +
          geom_errorbar(width = .2, position = position_dodge(0.9)) +
          theme_classic2() +
          rotate_x_text(angle = 45) +
          theme(legend.position = "none") +
          labs(title = input$selectGeneSymbol, x = NULL, y = "123_value")
      })
      
      output$plot <- renderPlot({
        p1()
      })
      
    }
    
    # Create Shiny app ----
    shinyApp(ui = ui, server = server)
就这样,

但是原始网络是这样的:

我知道我有必要解决它。但我不知道我的代码哪里出了问题,或者是Shining app server出现了问题

以下是我的示例代码:

    library(shiny)
    library(dplyr)
    library(tidyr)
    library(ggplot2)
    library(gridExtra)
    
    mean_data <- data.frame(
      Name = c(paste0("Group_", LETTERS[1:20])),
      matx <- matrix(sample(1:1000, 1000, replace = T), nrow = 20)
    )
    names(mean_data)[-1] <- c(paste0("Gene_", 1:50))
    
    sd_data <- data.frame(
      Name = c(paste0("Group_", LETTERS[1:20])),
      matx <- matrix(runif(1000, 5, 10), nrow = 20)
    )
    names(sd_data)[-1] <- c(paste0("Gene_", 1:50))
    
    
    ###
    ui <- fluidPage(
      
      pageWithSidebar(
        headerPanel("123"),
        sidebarPanel(
          selectInput(
            "selectGeneSymbol",
            "123:",
            choices = colnames(mean_data)[-1],
            multiple =F,
            width = 400,
            selected = 1
          ),
          
          actionButton(inputId = "plot1", label = "FPKM"),
          tags$h6(tags$a(href="https://www.ncbi.nlm.nih.gov/", "link"))
        ),
        mainPanel(
          plotOutput("plot")
          #uiOutput("all")
        )
      )
      
    )
    
    server <- function(input, output, session) {
      
      ## put sd into mean_data
      plotdata <- eventReactive(input$plot1, { 
        df <- mean_data %>% mutate(sd = sd_data[,input$selectGeneSymbol])
      })
      
      p1 <- eventReactive(input$plot1, {
        ggplot(data = plotdata(), aes(x = Name, y = .data[[input$selectGeneSymbol]], fill=Name,
                                      ymin = .data[[input$selectGeneSymbol]] - sd, ymax = .data[[input$selectGeneSymbol]] + sd )) +
          geom_bar(stat = "identity", position = position_dodge(0.9), width = 0.9) +
          # geom_errorbar(aes(ymin = plotdata()[,input$selectGeneSymbol] - sddata()[,input$selectGeneSymbol], ymax = plotdata()[,input$selectGeneSymbol] + sddata()[,input$selectGeneSymbol]), width = .2, position = position_dodge(0.9)) +
          geom_errorbar(width = .2, position = position_dodge(0.9)) +
          theme_classic2() +
          rotate_x_text(angle = 45) +
          theme(legend.position = "none") +
          labs(title = input$selectGeneSymbol, x = NULL, y = "123_value")
      })
      
      output$plot <- renderPlot({
        p1()
      })
      
    }
    
    # Create Shiny app ----
    shinyApp(ui = ui, server = server)
库(闪亮)
图书馆(dplyr)
图书馆(tidyr)
图书馆(GG2)
图书馆(gridExtra)

平均数据这里是我的答案:

library(shiny)
    library(dplyr)
    library(tidyr)
    library(ggplot2)
    library(gridExtra)
    
    mean_data <- data.frame(
      Name = c(paste0("Group_", LETTERS[1:20])),
      matx <- matrix(sample(1:1000, 1000, replace = T), nrow = 20)
    )
    names(mean_data)[-1] <- c(paste0("Gene_", 1:50))
    
    sd_data <- data.frame(
      Name = c(paste0("Group_", LETTERS[1:20])),
      matx <- matrix(runif(1000, 5, 10), nrow = 20)
    )
    names(sd_data)[-1] <- c(paste0("Gene_", 1:50))
    
    
    ###
    ui <- fluidPage(
      
      pageWithSidebar(
        headerPanel("123"),
        sidebarPanel(
          selectInput(
            "selectGeneSymbol",
            "123:",
            choices = colnames(mean_data)[-1],
            multiple =F,
            width = 400,
            selected = 1
          ),
          
          actionButton(inputId = "plot1", label = "FPKM"),
          tags$h6(tags$a(href="https://www.ncbi.nlm.nih.gov/", "link",target = "_blank"))
        ),
        mainPanel(
          plotOutput("plot")
          #uiOutput("all")
        )
      )
      
    )
    
    server <- function(input, output, session) {
      
      ## put sd into mean_data
      plotdata <- eventReactive(input$plot1, { 
        df <- mean_data %>% mutate(sd = sd_data[,input$selectGeneSymbol])
      })
      
      p1 <- eventReactive(input$plot1, {
        ggplot(data = plotdata(), aes(x = Name, y = .data[[input$selectGeneSymbol]], fill=Name,
                                      ymin = .data[[input$selectGeneSymbol]] - sd, ymax = .data[[input$selectGeneSymbol]] + sd )) +
          geom_bar(stat = "identity", position = position_dodge(0.9), width = 0.9) +
          # geom_errorbar(aes(ymin = plotdata()[,input$selectGeneSymbol] - sddata()[,input$selectGeneSymbol], ymax = plotdata()[,input$selectGeneSymbol] + sddata()[,input$selectGeneSymbol]), width = .2, position = position_dodge(0.9)) +
          geom_errorbar(width = .2, position = position_dodge(0.9)) +
          theme_classic2() +
          rotate_x_text(angle = 45) +
          theme(legend.position = "none") +
          labs(title = input$selectGeneSymbol, x = NULL, y = "123_value")
      })
      
      output$plot <- renderPlot({
        p1()
      })
      
    }
    
    # Create Shiny app ----
    shinyApp(ui = ui, server = server)
库(闪亮)
图书馆(dplyr)
图书馆(tidyr)
图书馆(GG2)
图书馆(gridExtra)

mean_data刚刚看到了你的问题,你的解决方案也应该是我推荐的。做得好!为了让其他人从您的见解中受益,您是否会将您的解决方案作为答案发布?这是完全合法的,甚至是受到鼓励的,因此人们可以接受自己的答案。您获得了声誉,用户可以从您的回答中受益。现在看来你的问题没有得到回答,这是一种误导。@Jan谢谢你的关注。我已经把我的答案贴在下面了。谢谢你的鼓励。我也很高兴与大家分享知识。