gpt4 book ai didi

r - Shiny 的选择使用操作按钮或其他东西转到不同的 tabPanel

转载 作者:行者123 更新时间:2023-12-04 12:08:55 26 4
gpt4 key购买 nike

我为我 Shiny 的应用程序构建了以下模板。

      ##ui.R
shinyUI(navbarPage("My Application",
tabPanel
(
"Select Data range",
sidebarLayout
(
sidebarPanel
(
h3("Select Data Range"),
selectInput("select", label = h3("Select Sector"),choices = list("Sector 1" = 1, "Sector 2" = 2,"Sector 3" = 3), selected = 1),br(),
dateRangeInput("dates", label = h3("Select Date range")),br(),
submitButton("Submit"),br(),
actionButton("action", label = "Proceed to select resolution")
),
mainPanel("Output")
)
),

tabPanel
(
"Select Resolution",
sidebarLayout
(
sidebarPanel
(
h3("Select Resolution"),
numericInput("num", label = h3("Select X-Grid Size"), value = 2),br(),
numericInput("num", label = h3("Select Y-Grid Size"), value = 2),br(),
numericInput("num", label = h3("Outlier Removal"), value = 2),br(),
numericInput("num", label = h3("Frequency"), value = 2),br(),
submitButton("Submit"),br(),
#actionButton("action", label = "Proceed to Service Parameters")
),
mainPanel("Output")
)
)

))

并且服务器文件暂时保持为空:
      ##server.R
shinyServer(function(input, output) {
})

问题是理想情况下我想在第一个 tabPanel 上使用类似操作按钮的输入来导航到第二个选项卡面板。任何有关替代方案的建议将同样受到赞赏。

最佳答案

您可以发送自定义消息:

用户界面

shinyUI(navbarPage("My Application",

tabPanel
(
"Select Data range",
sidebarLayout
(
sidebarPanel
(tags$head(tags$script('
Shiny.addCustomMessageHandler("myCallbackHandler",
function(typeMessage) {console.log(typeMessage)
if(typeMessage == 1){
console.log("got here");
$("a:contains(Select Resolution)").click();
}
if(typeMessage == 2){
$("a:contains(Select Data range)").click();
}
});
')),
h3("Select Data Range"),
selectInput("select", label = h3("Select Sector"),choices = list("Sector 1" = 1, "Sector 2" = 2,"Sector 3" = 3), selected = 1),br(),
dateRangeInput("dates", label = h3("Select Date range")),br(),
actionButton("action", label = "Proceed to select resolution")
),
mainPanel("Output")
)
),

tabPanel
(
"Select Resolution",
sidebarLayout
(
sidebarPanel
(
h3("Select Resolution"),
numericInput("num1", label = h3("Select X-Grid Size"), value = 2),br(),
numericInput("num2", label = h3("Select Y-Grid Size"), value = 2),br(),
numericInput("num3", label = h3("Outlier Removal"), value = 2),br(),
numericInput("num4", label = h3("Frequency"), value = 2),br(),
actionButton("action1", label = "Proceed to Service Parameters")

),
mainPanel("Output"),

)
)

))

服务器
library(shiny)
shinyServer(function(input, output,session) {
observe({
if(input$action > 0){
print('1')
session$sendCustomMessage("myCallbackHandler", "1")
}
})
observe({
if(input$action1 > 0){
print('2')
session$sendCustomMessage("myCallbackHandler", "2")
}
})
}
)

此外,您不能拥有具有相同 ID 的对象。记下您所有的 numericInputactionButton有相同的id。此外,我删除了提交按钮,但不确定您是否需要其中之一。

关于r - Shiny 的选择使用操作按钮或其他东西转到不同的 tabPanel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25920548/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com