我从数据库初始加载数据server.R需要几秒钟.在此之前,显示的页面会失真(选择框中的数据错误,框的奇怪位置,见下文).

我希望在数据完全加载之前显示不同的页面(或至少在我的第一个显示的选项卡中显示不同的内容).
我想过做某种conditionalPanel使用基于专用的全局变量(initial_loading_done)的条件,但无论我试着放置conditionalPanel没有奏效.
这是我的UI.R的结构:
shinyUI(
dashboardPage(
dashboardHeader(title = "Title"),
dashboardSidebar(
sidebarMenu(
menuItem("Tab1", tabName = "Tab1",icon = icon("dashboard")),
menuItem("Tab2", tabName = "Tab2", icon = icon("bar-chart-o"))
)
),
dashboardBody(
includeCSS("custom_css.css"),
tabItems(
tabItem(tabName = "Tab1",
fluidRow(<content>),
mainPanel(
fluidRow(<content>)
)
),
tabItem(tabName = "Tab2",
fluidRow(<content>),
mainPanel(
dataTableOutput('my_data_table')
)
)
)
)
)
)
Run Code Online (Sandbox Code Playgroud) 我的 Shiny 应用中有一个数据表。默认情况下,列名是数据集的列名。我想更改显示的列名,而不触及数据集本身。
我发现这个文档正是我需要的,但我不确定如何将其转换为 R 语法。
这是我呈现表格的当前方式:
output$score_data_table <- renderDataTable({
selectedArea_overview_TC()},
options = list(orderClasses = TRUE,
lengthMenu = list(c(15,25,50,100,-1), c('15','25','50','100','All')),
pageLength = 15,
order=list(1, 'desc'))
)
Run Code Online (Sandbox Code Playgroud)
我尝试columnDefs以多种方式添加该选项,但没有任何效果。
任何提示将不胜感激!
我有一个包含 ID 和位置的 data.table。例如,这是其中一行:(它有列名和行名,不知道这是否重要)
locations<-data.table(c(11,12),c(-159.58,0.2),c(21.901,22.221))
colnames(locations)<-c("id","location_lon","location_lat")
rownames(locations)<-c("1","2")
Run Code Online (Sandbox Code Playgroud)
然后我想迭代这些行并将它们与另一个点(经纬度)进行比较。在 for 循环中它的工作原理:
for (i in 1:nrow(locations)) {
loc <- locations[i,]
dist <- gdist(-159.5801, 21.901, loc$location_lon, loc$location_lat, units="m")
if(dist <= 50) {
return (loc)
}
return (NULL)
}
Run Code Online (Sandbox Code Playgroud)
并返回:
id 地点经度 地点纬度
1:11 -159.58 21.901
但我想使用应用。以下代码无法运行:
dists <- apply(locations,1,function(x) if (50 - gdist(-159.5801, 21.901, x$location_lon, x$location_lat, units="m")>=0) x else NULL)
Run Code Online (Sandbox Code Playgroud)
有$ operator is invalid for atomic vectors错误。更改为按位置引用 ( x[2],x[3]) 不足以解决此问题,我明白
Error in if (radius - gdist(lon, lat, x[2], x[3], units …Run Code Online (Sandbox Code Playgroud) 我想在同一行显示4个infoBoxes(或valueBoxes,我真的不在乎),它似乎不起作用......
这是一个工作的简化版本的代码,基于Rstudio wesite上的shinydashbaord教程(我使用的是infoBoxOutputs,但我想这里的格式无关紧要):
ui <- dashboardPage(
dashboardHeader(title = "Info boxes"),
dashboardSidebar(),
dashboardBody(
# infoBoxes with fill=FALSE
fluidRow(
infoBox("1st", 10 * 2, icon = icon("credit-card")),
infoBox("2nd", 10 * 2, icon = icon("credit-card")),
infoBox("3rd", 10 * 2, icon = icon("credit-card")),
)
)
)
Run Code Online (Sandbox Code Playgroud)
它在同一行显示3个infoBox.但是,一旦我再添加一个infoBox,它就会移动到一个新行:
ui <- dashboardPage(
dashboardHeader(title = "Info boxes"),
dashboardSidebar(),
dashboardBody(
# infoBoxes with fill=FALSE
fluidRow(
infoBox("1st", 10 * 2, icon = icon("credit-card")),
infoBox("2nd", 10 * 2, icon = icon("credit-card")),
infoBox("3rd", 10 * 2, icon = icon("credit-card")),
infoBox("4th", 10 * …Run Code Online (Sandbox Code Playgroud)