我的Shiny服务器中有以下代码。我的意图是每次单击UI上的refreshData按钮时,都会查询数据库,并在summaryPlot中使用此数据。有没有办法在首次加载Shiny应用程序时触发完全相同的数据库查询?
using System.Runtime.InteropServices;
namespace CSharpLibrary
{
public class TestCS
{
[DllImport("CPPLibrary")]
public static extern float TestMultiply(float a, float b);
[DllImport("CPPLibrary")]
public static extern string CPPOwnerName(int ind);
[DllImport("CPPLibrary")]
public static extern int GetInt();
[DllImport("CPPLibrary")]
public static extern int DoubleIntCPP(int num);
public static float SharpMultiply(float a, float b)
{
return a * b;
}
public static string CSharpOwnerName()
{
return "Shubham Singh. C#";
}
public static int GetInteger()
{
return 2;
}
}
}
谢谢!
答案 0 :(得分:2)
您可以将参数ignoreNull = FALSE
添加到eventReactive
。下面给出一个工作实例。希望这有帮助!
shinyApp(ui,server)
library(shiny)
ui <- fluidPage(
actionButton('refreshData','Refresh!'),
tableOutput('summaryTable')
)
server <- function(input, output, session){
df = eventReactive (input$refreshData, ignoreNULL = F, {
mtcars[sample(seq(nrow(mtcars)),5),]
})
output$summaryTable = renderTable({
head(df())
})
}
shinyApp(ui,server)
将此与不使用ignoreNull
参数的应用程序的行为进行比较:
library(shiny)
ui <- fluidPage(
actionButton('refreshData','Refresh!'),
tableOutput('summaryTable')
)
server <- function(input, output, session){
df = eventReactive (input$refreshData, {
mtcars[sample(seq(nrow(mtcars)),5),]
})
output$summaryTable = renderTable({
head(df())
})
}