If 语句在闪亮的应用程序中连续 2 次不起作用
If statement does not work 2 times in a row in a shiny app
我有一个闪亮的应用程序,它显示 3 个选项卡。
在 Documents
选项卡中有一个 table。当用户单击第一行的 setosa
时,他将移动到 View
选项卡(仅在单击发生时可见)并看到 table。当用户单击第二行的 setosa
时,他将移动到 View
选项卡并看到另一个 table。此外,那些 table 必须仅在 View
选项卡上可见。
该应用程序似乎运行良好,但如果我点击第一行 setosa
,移至 View
选项卡,再次 return 移至 Documents
选项卡,然后尝试再次点击第一行 setosa
没有任何反应。我必须单击第二行 setosa
才能使其再次运行。第二行 setosa
.
也是如此
简而言之,我不能连续两次执行相同的操作,我觉得我的 if
状况是造成这种情况的原因。
library(shiny)
library(shinydashboard)
library(shinyWidgets)
library(shinydashboardPlus)
library(DT)
library(shinyjs)
shinyApp(
ui = dashboardPagePlus(
header = dashboardHeaderPlus(title = span(strong("ArmorDoc"),style = "color: black;")
),
sidebar = dashboardSidebar(
),
body = dashboardBody(
useShinyjs(),
tags$hr(),
tabsetPanel(
id ="tabA",
type = "tabs",
tabPanel("Documents",icon = icon("accusoft"),
tags$hr(),
DTOutput("dt1")),
tabPanel("View", icon = icon("table"),
DTOutput("dt3")
),
tabPanel("Upload", icon = icon("table")
)
)
)),
server = function(input, output,session) {
observeEvent(input$tabA, {
if(input$tabA == "Documents"|input$tabA=="Upload"){
hideTab("tabA", "View")
}
})
observeEvent(input$dt1_cell_clicked, {
# alternative: input$dt1_cells_selected
if (req(input$dt1_cell_clicked$value) == "setosa") {
showTab("tabA", "View")
updateTabsetPanel(session, inputId = "tabA", selected = "View")
}
})
output$dt1 <- DT::renderDataTable({
DT::datatable(
iris[1:2,],
filter = "top",
options = list(searchHighlight = TRUE, search = list(search = ""),pageLength = 5,columnDefs = list(list(className = 'dt-left', targets = "_all"))),rownames= FALSE,
selection = list(mode = 'single', target = 'cell')
)
})
output$dt3 <- renderDT(server = F,
if(input$dt1_cell_clicked$row == 1&input$tabA=="View"){
datatable(iris)
}
else if(input$dt1_cell_clicked$row == 2&input$tabA=="View"){
datatable(mtcars)
}
else{
return(NULL)
}
)
}
)
可以找到答案。它与 observeEvent()
.
中的 Proxy
方法相同
我有一个闪亮的应用程序,它显示 3 个选项卡。
在 Documents
选项卡中有一个 table。当用户单击第一行的 setosa
时,他将移动到 View
选项卡(仅在单击发生时可见)并看到 table。当用户单击第二行的 setosa
时,他将移动到 View
选项卡并看到另一个 table。此外,那些 table 必须仅在 View
选项卡上可见。
该应用程序似乎运行良好,但如果我点击第一行 setosa
,移至 View
选项卡,再次 return 移至 Documents
选项卡,然后尝试再次点击第一行 setosa
没有任何反应。我必须单击第二行 setosa
才能使其再次运行。第二行 setosa
.
简而言之,我不能连续两次执行相同的操作,我觉得我的 if
状况是造成这种情况的原因。
library(shiny)
library(shinydashboard)
library(shinyWidgets)
library(shinydashboardPlus)
library(DT)
library(shinyjs)
shinyApp(
ui = dashboardPagePlus(
header = dashboardHeaderPlus(title = span(strong("ArmorDoc"),style = "color: black;")
),
sidebar = dashboardSidebar(
),
body = dashboardBody(
useShinyjs(),
tags$hr(),
tabsetPanel(
id ="tabA",
type = "tabs",
tabPanel("Documents",icon = icon("accusoft"),
tags$hr(),
DTOutput("dt1")),
tabPanel("View", icon = icon("table"),
DTOutput("dt3")
),
tabPanel("Upload", icon = icon("table")
)
)
)),
server = function(input, output,session) {
observeEvent(input$tabA, {
if(input$tabA == "Documents"|input$tabA=="Upload"){
hideTab("tabA", "View")
}
})
observeEvent(input$dt1_cell_clicked, {
# alternative: input$dt1_cells_selected
if (req(input$dt1_cell_clicked$value) == "setosa") {
showTab("tabA", "View")
updateTabsetPanel(session, inputId = "tabA", selected = "View")
}
})
output$dt1 <- DT::renderDataTable({
DT::datatable(
iris[1:2,],
filter = "top",
options = list(searchHighlight = TRUE, search = list(search = ""),pageLength = 5,columnDefs = list(list(className = 'dt-left', targets = "_all"))),rownames= FALSE,
selection = list(mode = 'single', target = 'cell')
)
})
output$dt3 <- renderDT(server = F,
if(input$dt1_cell_clicked$row == 1&input$tabA=="View"){
datatable(iris)
}
else if(input$dt1_cell_clicked$row == 2&input$tabA=="View"){
datatable(mtcars)
}
else{
return(NULL)
}
)
}
)
可以找到答案observeEvent()
.
Proxy
方法相同