R 闪亮的导航栏添加其他信息
因为我的代码很长,所以我考虑了 我尝试从中添加以下代码(在lastR 闪亮的导航栏添加其他信息,r,shiny,R,Shiny,因为我的代码很长,所以我考虑了 我尝试从中添加以下代码(在lasttabPanel之后)。但是没有运气 tags$script(HTML("var header = $('.navbar > .container'); header.append('<div Company name text here>')")) 标记$script(HTML(“var头=$('.navbar>.container”); header.app
tabPanel
之后)。但是没有运气
tags$script(HTML("var header = $('.navbar > .container');
header.append('<div Company name text here>')"))
标记$script(HTML(“var头=$('.navbar>.container”);
header.append(''))
我只想在导航栏的右侧显示一个纯文本(信息)。下面的代码为您提供了所需的内容。主要的问题是旅游html标签
library(shiny)
server <- function(input, output, session) {
output$plot <- renderPlot({
plot(cars, type=input$plotType)
})
output$summary <- renderPrint({
summary(cars)
})
output$table <- DT::renderDataTable({
DT::datatable(cars)
})
}
ui <-shinyUI(navbarPage("Navbar!",
tabPanel("Plot",
sidebarLayout(
sidebarPanel(
radioButtons("plotType", "Plot type",
c("Scatter"="p", "Line"="l")
)
),
mainPanel(
plotOutput("plot")
)
)
),
tabPanel("Summary",
verbatimTextOutput("summary")
),
tags$script(HTML("var header = $('.navbar > .container');
header.append('<div style=\"float:right\"><h3>Company name text here</h3></div>');
console.log(header)"))
))
shinyApp(ui = ui, server = server)
库(闪亮)
容器流体);
header.append('Company name text here');
console.log(标题“”)
))
shinyApp(用户界面=用户界面,服务器=服务器)
唯一的变化是,在html脚本
.navbar>中,container
已更改为.navbar>.container fluid
我发现了另一种优雅/简约的方法,可以使用包“shinyjs”将文本添加到navbar中“,还有我想要的额外好处,可以在导航栏的右侧堆叠文本。它位于“服务器”中的“shinyjs::html()”函数中
库(闪亮)
ui@MLavoie谢谢你的提醒!我对答案进行了编辑,使其适用于最新的shinny
软件包。此代码对我适用,但它在laeft上添加了隐藏按钮,没有包含JS代码oftags%脚本的文本。
library(shiny)
server <- function(input, output, session) {
output$plot <- renderPlot({
plot(cars, type=input$plotType)
})
output$summary <- renderPrint({
summary(cars)
})
output$table <- DT::renderDataTable({
DT::datatable(cars)
})
}
ui <-shinyUI(navbarPage("Navbar!",
tabPanel("Plot",
sidebarLayout(
sidebarPanel(
radioButtons("plotType", "Plot type",
c("Scatter"="p", "Line"="l")
)
),
mainPanel(
plotOutput("plot")
)
)
),
tabPanel("Summary",
verbatimTextOutput("summary")
),
tags$script(HTML("var header = $('.navbar> .container-fluid');
header.append('<div style=\"float:right\"><h3>Company name text here</h3></div>');
console.log(header)"))
))
shinyApp(ui = ui, server = server)
library(shiny)
ui <- fluidPage(
shinyjs::useShinyjs(),#this line NEEDS to be somewhere in the ui!
navbarPage(
title = HTML("<b><u>Title</u></b>"),
id = 'banner'
)
)
server <- function(input, output) {
shinyjs::addClass(id = "banner", class = "navbar-right")#moves navbar right
#this next line is the one APPENDING text to the navbar, thanks to "add = TRUE"
shinyjs::html(id = "banner", html = "<p>companyName</p><p>company@place.com</p>", add = TRUE)
}
# Run the application
shinyApp(ui = ui, server = server)