如果在闪亮的应用程序中语句无法连续2次运行 [英] If statement does not work 2 times in a row in a shiny app
问题描述
我有一个闪亮的应用程序,它显示3个标签。
I have a shiny app which displays 3 tabs.
在 Documents
标签中有一个表格。当用户单击第一行的 setosa
时,他将移至 View
标签(仅在单击发生时可见) )并看到一张桌子。当用户单击第二行的 setosa
时,他将移至 View
标签,并看到另一个表。此外,这些表必须仅在查看
选项卡上可见。
In the Documents
tab there is a table. When the user clicks on the setosa
of the 1st row he is moving to the View
tab (visible only when click happens) and sees a table. When the user clicks on the setosa
of the 2nd row he is moving to the View
tab and sees another table. Also those tables must be visible only on View
tab.
该应用似乎正常运行,但是如果我单击第一行 setosa
,移至 View
选项卡,返回到 Documents
选项卡,然后尝试再次单击第一行 setosa
,没有任何反应。我必须单击第二行 setosa
使其再次起作用。第二行 setosa
也是如此。
The app seems to work fine but if I click on the 1st row setosa
,move to the View
tab, return to the Documents
tab again and try to click again the 1st row setosa
nothing happens. I have to click the 2nd row setosa
to make it work again. The same happens with the 2nd row setosa
.
简而言之,我无法在行,我觉得我的 if
条件对此负责。
In a few words I cannot do the same action twice in a row and I feel that my if
condition is responsible for this.
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
方法相同。
这篇关于如果在闪亮的应用程序中语句无法连续2次运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!