gpt4 book ai didi

javascript - 从服务器部分刷新 R Shiny session

转载 作者:太空宇宙 更新时间:2023-11-04 16:21:23 25 4
gpt4 key购买 nike

我的 R Shiny 应用程序加载信息,我希望在加载这些信息之前,自动刷新 session 。

类似的问题已被问过多次,但答案总是带有一个按钮。例如: Page refresh Button in R shiny

我尝试将重置代码包含在服务器部分的观察函数中,但没有成功:

observe({
jsResetCode <- "shinyjs.reset = function() {history.go(0)}" # Define the js method that resets the page
useShinyjs()
extendShinyjs(text = jsResetCode)
})

如何从函数内自动刷新 R Shiny session ?

最佳答案

我必须查看完整的代码才能帮助您。看看这些是否能帮助你。玩得开心

library(shiny)
library(shinydashboard)


dat = data.frame(id = c("d","a","c","b"), a = c(1,2,3,4), b = c(6,7,8,9))

header <- dashboardHeader(

)

sidebar <- dashboardSidebar(
tags$head(tags$style(HTML('.content-wrapper { height: 1500px !important;}'))),
sidebarMenu (
menuItem("A", tabName = "d1"),
menuItem("B", tabName = "d2"),
menuItem("C", tabName = "d3")
)
)

body <- dashboardBody(

tabItems(
tabItem(tabName = "d1",
box(title = "AAA",
actionButton("refreshTab1_id", "Refresh Tab 1"),
actionButton("sortTable1_id", "Sort Table 1"),
DT::dataTableOutput("table_for_tab_1", width = "100%"))
),
tabItem(tabName = "d2",
box(title = "BBB",
actionButton("refreshTab2_id", "Refresh Tab 2"),
actionButton("sortTable2_id", "Sort Table 2"),
DT::dataTableOutput("table_for_tab_2", width = "100%"))
),
tabItem(tabName = "d3",
box(title = "CCC",
actionButton("refreshTab3_id", "Refresh Tab 3"),
actionButton("sortTable3_id", "Sort Table 3"),
DT::dataTableOutput("table_for_tab_3", width = "100%"))
)
)
)

# UI
ui <- dashboardPage(header, sidebar, body)

# Server
server <- function(input, output, session) {


observe({

if (input$sortTable1_id || input$sortTable2_id || input$sortTable3_id) {
dat_1 = dat %>% dplyr::arrange(id)
} else {
dat_1 = dat
}

output$table_for_tab_1 <- output$table_for_tab_2 <- output$table_for_tab_3 <- DT::renderDataTable({

DT::datatable(dat_1,
filter = 'bottom',
selection = "single",
colnames = c("Id", "A", "B"),
options = list(pageLength = 10,
autoWidth = TRUE#,
# columnDefs = list(list(targets = 9,
# visible = FALSE))
)
)
})
})

observe({
if (input$refreshTab1_id || input$refreshTab2_id || input$refreshTab3_id) {
session$reload()
}
})

}

# Shiny dashboard
shiny::shinyApp(ui, server)

关于javascript - 从服务器部分刷新 R Shiny session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40618432/

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