根据闪亮的仪表板中的条件显示两个动态绘图和高图绘图

时间:2019-10-02 22:41:31

标签: r shiny

下面有一个发光的仪表板,您最初可以在其中看到selecctinput()。当用户选择Return Analysis时,将创建第二个selectInput()。对于前两个选择中的每个,应显示不同的图。问题是我需要将显示的图显示在顶部,而现在将高图显示在底部。

#ui.r
library(shiny)
library(shinydashboard)
library(plotly)
library(highcharter)
ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(
    selectInput("sec","Page",choices=c("Introduction","Return Analysis"),selected = "Introduction"),
    uiOutput("tab")

  ),
  dashboardBody(
    plotlyOutput("plot"),
    highchartOutput("hc2")
  )
)
#server.r
server <- function(input, output) { 
  output$tab<-renderUI({
    if(input$sec=="Introduction"){
      return(NULL)
    }
    else if(input$sec=="Return Analysis"){

      selectInput("tb", "Tabs",choices=c("Monthly Returns","Monthly Returns(Histogram)","Annual Returns"),selected = "Monthly Returns")
    }
  })

  output$plot <- renderPlotly({
    if(input$sec=="introduction"){
      return(NULL)
    }
    else if(input$tb=="Monthly Returns"){
      plot_ly(mtcars, x = ~mpg, y = ~wt)

    }
    else{
      return(NULL)
    }
  })
  output$hc2 <- renderHighchart({
    if(input$sec=="Introduction"){
      return(NULL)
    }
    else if(input$tb=="Monthly Returns(Histogram)"){
      data(diamonds, mpg, package = "ggplot2")

      hchart(mpg, "scatter", hcaes(x = displ, y = hwy, group = class))
    }

    else{
      return(NULL)
    }
  })

  }

1 个答案:

答案 0 :(得分:1)

这是同时使用const str = "(*#*) <p>The video was posted on Facebook and shows a shirtless man repeatedly throwing rocks at a wombat as it tries to (*#*) run away.</p>"; const first_str = `<div class="photo"><img src="'+media+'"></div>`; const second_str = `<a class="relatednews" href="'+linkStr+'">'linkName'</a>`; const regex = /(\(\*\#\*\))(.*?)(\(\*\#\*\))(.*)/; const replacement = `${first_str}$2${second_str}$4`; const result = str.replace(regex, replacement); // <div class="photo"><img src="'+media+'"></div> <p>The video was posted on Facebook and shows a shirtless man repeatedly throwing rocks at a wombat as it tries to <a class="relatednews" href="'+linkStr+'">'linkName'</a> run away.</p> highchart的解决方案。我们有一个plotly可以将图表发送到UI,还有一个renderUI可以监视用户输入并生成图形和reactive处理程序。

*Output