Shiny RStudio操作按钮已忽略
由Shiny RStudio操作按钮已忽略,shiny,rstudio,Shiny,Rstudio,由actionButton触发的server.R中的input$goButton是否应该在RStudio中的if语句中?闪亮网页上的示例显示: library(shiny) shinyUI(pageWithSidebar( headerPanel("Click the button"), sidebarPanel( sliderInput("obs", "Number of observations:", min = 0, max = 1000,
actionButton
触发的server.R中的input$goButton
是否应该在RStudio中的if
语句中?闪亮网页上的示例显示:
library(shiny)
shinyUI(pageWithSidebar(
headerPanel("Click the button"),
sidebarPanel(
sliderInput("obs", "Number of observations:",
min = 0, max = 1000, value = 500),
actionButton("goButton", "Go!")
),
mainPanel(
plotOutput("distPlot")
)
))
及
有什么想法吗?我知道这是你想要的吗?无论何时按下按钮,它都会增加计数+1(从0开始),因此如果未按下按钮,则会出现带有
return()
的and if语句“nothing”
rm(list = ls())
library(shiny)
runApp(list(ui = pageWithSidebar(
headerPanel("Click the button"),
sidebarPanel(
sliderInput("obs", "Number of observations:",min = 0, max = 1000, value = 500),
actionButton("goButton", "Go!")
),
mainPanel(plotOutput("distPlot"))),
server = function(input, output,session) {
my_data <- reactive({
if(input$goButton == 0)
{
return()
}
isolate({
input$goButton
dist <- isolate(rnorm(input$obs))
hist(dist, main=isolate(paste(system(paste("echo", dist[1],"> /tmp/1 && md5sum /tmp/1"),intern=TRUE),collapse='')))
})
})
output$distPlot <- renderPlot({my_data()
})
}
)
)
rm(list=ls())
图书馆(闪亮)
runApp(列表(ui=pageWithSidebar(
headerPanel(“单击按钮”),
侧栏面板(
sliderInput(“obs”,“观察次数:”,最小值=0,最大值=1000,值=500),
动作按钮(“goButton”,“Go!”)
),
主面板(绘图输出(“distPlot”),
服务器=功能(输入、输出、会话){
my_dataI这是您想要的吗?无论何时按下按钮,它都会增加计数+1(从0开始),因此,如果未按下按钮,则会出现带有return()
的and if语句“nothing”
rm(list = ls())
library(shiny)
runApp(list(ui = pageWithSidebar(
headerPanel("Click the button"),
sidebarPanel(
sliderInput("obs", "Number of observations:",min = 0, max = 1000, value = 500),
actionButton("goButton", "Go!")
),
mainPanel(plotOutput("distPlot"))),
server = function(input, output,session) {
my_data <- reactive({
if(input$goButton == 0)
{
return()
}
isolate({
input$goButton
dist <- isolate(rnorm(input$obs))
hist(dist, main=isolate(paste(system(paste("echo", dist[1],"> /tmp/1 && md5sum /tmp/1"),intern=TRUE),collapse='')))
})
})
output$distPlot <- renderPlot({my_data()
})
}
)
)
rm(list=ls())
图书馆(闪亮)
runApp(列表(ui=pageWithSidebar(
headerPanel(“单击按钮”),
侧栏面板(
sliderInput(“obs”,“观察次数:”,最小值=0,最大值=1000,值=500),
动作按钮(“goButton”,“Go!”)
),
主面板(绘图输出(“distPlot”),
服务器=功能(输入、输出、会话){
my_dataI这是您想要的吗?无论何时按下按钮,它都会增加计数+1(从0开始),因此,如果未按下按钮,则会出现带有return()
的and if语句“nothing”
rm(list = ls())
library(shiny)
runApp(list(ui = pageWithSidebar(
headerPanel("Click the button"),
sidebarPanel(
sliderInput("obs", "Number of observations:",min = 0, max = 1000, value = 500),
actionButton("goButton", "Go!")
),
mainPanel(plotOutput("distPlot"))),
server = function(input, output,session) {
my_data <- reactive({
if(input$goButton == 0)
{
return()
}
isolate({
input$goButton
dist <- isolate(rnorm(input$obs))
hist(dist, main=isolate(paste(system(paste("echo", dist[1],"> /tmp/1 && md5sum /tmp/1"),intern=TRUE),collapse='')))
})
})
output$distPlot <- renderPlot({my_data()
})
}
)
)
rm(list=ls())
图书馆(闪亮)
runApp(列表(ui=pageWithSidebar(
headerPanel(“单击按钮”),
侧栏面板(
sliderInput(“obs”,“观察次数:”,最小值=0,最大值=1000,值=500),
动作按钮(“goButton”,“Go!”)
),
主面板(绘图输出(“distPlot”),
服务器=功能(输入、输出、会话){
my_dataI这是您想要的吗?无论何时按下按钮,它都会增加计数+1(从0开始),因此,如果未按下按钮,则会出现带有return()
的and if语句“nothing”
rm(list = ls())
library(shiny)
runApp(list(ui = pageWithSidebar(
headerPanel("Click the button"),
sidebarPanel(
sliderInput("obs", "Number of observations:",min = 0, max = 1000, value = 500),
actionButton("goButton", "Go!")
),
mainPanel(plotOutput("distPlot"))),
server = function(input, output,session) {
my_data <- reactive({
if(input$goButton == 0)
{
return()
}
isolate({
input$goButton
dist <- isolate(rnorm(input$obs))
hist(dist, main=isolate(paste(system(paste("echo", dist[1],"> /tmp/1 && md5sum /tmp/1"),intern=TRUE),collapse='')))
})
})
output$distPlot <- renderPlot({my_data()
})
}
)
)
rm(list=ls())
图书馆(闪亮)
runApp(列表(ui=pageWithSidebar(
headerPanel(“单击按钮”),
侧栏面板(
sliderInput(“obs”,“观察次数:”,最小值=0,最大值=1000,值=500),
动作按钮(“goButton”,“Go!”)
),
主面板(绘图输出(“distPlot”),
服务器=功能(输入、输出、会话){
这里的我的数据显示,依赖关系在goButton上,因为它在反应式表达式中。这样看,如果您希望依赖按钮,那么只需在反应式表达式中键入input$goButton,每次单击它,反应式表达式都将被执行。在我比较复杂的示例中,我有一组调用的isolate()
调用。这可能是在goButton之前触发它的原因吗?在响应调用中是否可以有多个isolate()
调用?提供示例,然后我将能够看到问题的确切来源is@pops我想我把范围缩小到system()
无论按钮是什么,命令都会被触发。我更新了我的示例。因此,您希望仅在按下按钮时绘制hist吗?这里显示的是,依赖项位于goButton上,因为它位于反应式表达式中。这样看,如果您希望依赖于按钮,只需在反应式表达式中键入input$goButton即可Session,每次单击它时,都会执行反应式表达式。在我比较复杂的示例中,我有一组isolate()
调用。这可能是它在goButton之前被触发的原因吗?我可以有多个isolate())
在响应式呼叫中?提供您的示例,然后我将能够看到问题的确切来源is@pops我想我把范围缩小到system()
无论按钮是什么,命令都会被触发。我更新了我的示例。因此,您希望仅在按下按钮时绘制hist吗?这里显示的是,依赖项位于goButton上,因为它位于反应式表达式中。这样看,如果您希望依赖于按钮,只需在反应式表达式中键入input$goButton即可Session,每次单击它时,都会执行反应式表达式。在我比较复杂的示例中,我有一组isolate()
调用。这可能是它在goButton之前被触发的原因吗?我可以有多个isolate())
在响应式呼叫中?提供您的示例,然后我将能够看到问题的确切来源is@pops我想我把范围缩小到system()
无论按钮是什么,命令都会被触发。我更新了我的示例。因此,您希望仅在按下按钮时绘制hist吗?这里显示的是,依赖项位于goButton上,因为它位于反应式表达式中。这样看,如果您希望依赖于按钮,只需在反应式表达式中键入input$goButton即可Session,每次单击它时,都会执行反应式表达式。在我比较复杂的示例中,我有一组isolate()
调用。这可能是它在goButton之前被触发的原因吗?我可以有多个isolate())
在响应式呼叫中?提供您的示例,然后我将能够看到问题的确切来源is@pops我想我把范围缩小到system()
无论按钮是什么,命令都会被触发。我更新了我的示例。因此,您希望仅在按下按钮时绘制hist吗?这非常有效。我没想到我必须将input$goButton
显示两次,一次在if return()中,另一次在大隔离()中。谢谢。它不应该在隔离()中一点也不。它什么也没做。这非常有效。我没想到我会有input$goButton
两次出现,一次出现在if return()中,另一次出现在一个大的隔离()中。谢谢。它