从HTML文本(嵌套在shinyServer中)链接到特定的闪亮选项卡面板(在shinyUI中)
我正在寻找一种从HTML文本(嵌套在服务器部件中)链接到特定闪亮选项卡面板(嵌套在UI中)的方法。假设我们有以下应用程序:从HTML文本(嵌套在shinyServer中)链接到特定的闪亮选项卡面板(在shinyUI中),r,shiny,R,Shiny,我正在寻找一种从HTML文本(嵌套在服务器部件中)链接到特定闪亮选项卡面板(嵌套在UI中)的方法。假设我们有以下应用程序: library(shiny) shinyUI(fluidPage( sidebarLayout( mainPanel( tabsetPanel( type="tabs", tabPanel("Contents", htmlOutput("contents")), tabPanel("Plot", pl
library(shiny)
shinyUI(fluidPage(
sidebarLayout(
mainPanel(
tabsetPanel(
type="tabs",
tabPanel("Contents", htmlOutput("contents")),
tabPanel("Plot", plotOutput("plot")) # <- A link to here
)
)
)
))
shinyServer(function(input, output) {
output$contents <- renderText({
HTML("A link to <a href='#Plot'>Plot</a>") # <- from there
})
output$plot({
some ggplot
})
})
库(闪亮)
shinyUI(fluidPage)(
侧边栏布局(
主面板(
选项卡面板(
type=“tabs”,
选项卡面板(“内容”,htmlOutput(“内容”),
tabPanel(“Plot”,plotOutput(“Plot”)#我不知道这是否可以通过链接实现。但是您可以使用按钮和updateTabsetPanel
library(shiny)
library(ggplot2)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(),
mainPanel(
tabsetPanel(
type="tabs",
id = "tabset",
tabPanel("Contents", actionButton("go", "Go to plot")),
tabPanel("Plot", plotOutput("plot"))
)
)
)
)
server <- function(input, output, session) {
observeEvent(input$go, {
updateTabsetPanel(session, "tabset", "Plot")
})
output$plot <- renderPlot({
ggplot(mtcars, aes(x=cyl, y=disp)) + geom_point()
})
}
shinyApp(ui, server)
库(闪亮)
图书馆(GG2)
ui感谢Stéphane Laurent为我指明了正确的方向,我成功地创建了我想要的解决方案。为了在服务器功能中保留所有HTML文本,我使用了renderUI
和actionLink
的组合。现在的解决方案如下所示:
library(shiny)
shinyUI(fluidPage(
sidebarLayout(
mainPanel(
tabsetPanel(
type="tabs",
id = "tabset", # <- Key element 1
tabPanel("Contents", htmlOutput("contents")),
tabPanel("Plot", plotOutput("plot"))
)
)
)
))
shinyServer(function(input, output, session) {
output$contents <- renderUI({ # <- Key element 2
list(
HTML(<p>Some text..</p>),
actionLink("link", "Link to Plot") # <- Key element 3
)
})
observeEvent(input$link, {updateTabsetPanel(session, "tabset", "Plot")}) # <- Key element 4
output$plot({
some ggplot
})
})
库(闪亮)
shinyUI(fluidPage)(
侧边栏布局(
主面板(
选项卡面板(
type=“tabs”,
id=“tabset”、#谢谢Stéphane!!你为我指明了正确的方向。幸运的是有一个actionLink
(每天都是上学日)。我将此与renderUI
结合使用,以保持服务器功能中的所有内容。我将很快发布我的解决方案。