我在 C 中有一个结构,其中成员是浮点数组。我想在编译时像这样初始化它:
typedef struct curve {
float *xs;
float *ys;
int n;
} curve;
curve mycurve1 = {
{1, 2, 3},
{4, 2, 9},
3
};
curve mycurve2 = {
{1, 2, 3, 4},
{0, 0.3, 0.9, 1.5},
4
};
Run Code Online (Sandbox Code Playgroud)
但我收到编译错误。
一种可能的解决方案可能是在结构中使用数组而不是指针。这是这里一个非常相似的问题的公认答案:https : //stackoverflow.com/a/17250527/1291302,但这种方法的问题是我不知道 typedef 时的数组大小。不仅如此,我可能还想初始化另一个更大的曲线。
另一种方法可能是使用 malloc,但我发现这有点矫枉过正,因为我在编译时知道数组大小,而且我不需要在运行时更改它。
我不知道其他可能有用的方法。也许将数组转换为指针?- 我真的不知道我会如何处理。
最小可重现示例:
library("shiny")
ui <- fluidPage(
actionButton("button1", "Run 1"),
actionButton("button2", "Run 2")
)
server <- function(session, input, output) {
cat("session starts\n")
observeEvent(input$button1, {
cat("1 starts\n")
Sys.sleep(15)
cat("1 stops\n")
})
observeEvent(input$button2, {
cat("2 starts\n")
Sys.sleep(15)
cat("2 stops\n")
})
}
shinyApp(ui = ui, server = server)
Run Code Online (Sandbox Code Playgroud)
每个按钮都模拟运行一些长时间占用 CPU 的算法。
问题:第二个按钮观察器无法独立启动。它会等到第一个会话中的第一次运行完成。我认为闪亮的会话是独立的。shiny 如何处理每个 R 会话的多个shiny 会话?如果多个用户想要同时连接到应用程序怎么办?
如何处理多个用户同时运行同一个应用程序?谢谢