下面有一个发光的仪表板,您最初可以在其中看到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)
}
})
}
答案 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