(自从我得到0个答案后,来自闪亮讨论Google小组的交叉帖子).
我不太了解R的消息vs cat vs print vs等,但我想知道是否有可能捕获消息以及他们是谁在一个闪亮的应用程序?
示例:以下应用程序可以捕获cat语句(以及print语句)但不捕获消息语句
runApp(shinyApp(
ui = fluidPage(
textOutput("test")
),
server = function(input,output, session) {
output$test <- renderPrint({
cat("test cat")
message("test message")
})
}
))
Run Code Online (Sandbox Code Playgroud)
链接到原始问题:https://groups.google.com/forum/#!topic/shiny-discuss/UCacIquFJQY
谢谢
我从数据库初始加载数据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) 这似乎是一个非常明显的问题,但我还没有找到关于这个主题的任何内容.
如何刷新闪亮的应用程序(相当于按下F5,或单击RStudio中的"重新加载应用程序"按钮)?
ui.R
shinyUI(pageWithSidebar(
headerPanel("Example"),
sidebarPanel(
actionButton("goButton", "Refresh")
),
mainPanel(
h4("I would really like to refresh this please.")
)
))
Run Code Online (Sandbox Code Playgroud)
server.R
shinyServer(function(input, output,session) {
observe({
if(input$goButton==0) return(NULL)
isolate({
#
# I would like to refresh my session here with some sort of
# function like session(refresh)...
})
})
})
Run Code Online (Sandbox Code Playgroud)
我不认为我想使用stopApp() - 我只想刷新它,使其处于加载时的状态.
UPDATE
在RStudio网站上,它显示了如何从服务器管理用户的会话.特别,
$ sudo rstudio-server suspend-session <pid>
Run Code Online (Sandbox Code Playgroud)
应用程序中是否存在与用户相同的功能?在会话信息的文档中(这里),它说有一个onSessionEnded(回调)函数.如果有session.End()函数执行上面的suspend-session函数会很好!
试图更新侧边栏在flexdashboard选项卡上单击时.无法让它发挥作用.
---
title: "Test Sidebar"
output:
flexdashboard::flex_dashboard:
orientation: rows
runtime: shiny
---
```{r setup}
library(flexdashboard)
library(shiny)
library(shinyjs)
useShinyjs(rmd = TRUE)
```
Sidebar {.sidebar data-width=250}
=======================================================================
```{r}
div(id = "one", selectInput("input1",label= "Show Always",choices=c("a","b","c")))
div(id = "two",selectInput("input2",label = "Show only on Tab 1", choices=c("d","e","f")))
```
<!-- Update the sidebar based on the tab chosen. Generated HTML code shown for tabs-->
Tab 1 <!-- <a href="#section-tab-1" aria-expanded="true" data-toggle="tab"> -->
=======================================================================
```{r}
useShinyjs(rmd = TRUE)
shinyjs::onclick("#section-tab-2",shinyjs::hide(id = "two"))
shinyjs::onclick("#section-tab-1",shinyjs::show(id = …Run Code Online (Sandbox Code Playgroud) 我已经构建了一个R/Shiny应用程序,它使用线性回归来预测某些指标.
为了使这个应用程序更具交互性,我需要添加一个折线图,在这里我可以拖动折线图的点,捕获新点并根据新点预测值.
基本上,我在RShiny中寻找类似的东西.有关如何实现这一目标的任何帮助?
我的闪亮应用程序生成一些用户可以下载的文件.为此,我已将下载按钮放在ui中.但是,当页面启动时,在完成任何计算之前,没有任何内容可供下载.我想阻止用户下载空白页面.
为此,我想在输出准备好之前禁用downloadButton.但我不知道该怎么做.我已经找到了禁用ActionButton的方法(比如ShinyBS包和其他JS代码),但是没有用于downloadButton的方法.
现在,如果输出没有准备好,我使用validate()来抛出错误.但是,当单击downloadButton时,会打开一个新的空网页,其中包含一条很难看的错误信息.
让我知道你的想法.
这是我的ui代码
downloadButton('download', 'Download Lasso component matrix')),
Run Code Online (Sandbox Code Playgroud)
这是我的服务器代码:
output$download_matrix <- downloadHandler(
filename = function() {
validate(
need(is.null(outputData())==FALSE, "No data to download yet")
)
paste('combined_model_matrix', '.txt', sep='') },
content = function(file) {
write.csv(outputData()$combinedAdjMtr, file)
})
Run Code Online (Sandbox Code Playgroud) 我希望Shiny根据矢量的大小打印出一些不同的颜色文本.我想的是:
output$some_text <- renderText({
if(length(some_vec) < 20){
paste("This is red text")
<somehow make it red>
}else{
paste("This is blue text")
<somehow make it blue>
Run Code Online (Sandbox Code Playgroud)
...但后来我才意识到,我在服务器上做这个,而不是用户界面.
而且,据我所知,我无法将此条件逻辑移动到UI中.
例如,这样的东西在UI中不起作用:
if(length(some_vec)< 20){
column(6, tags$div(
HTML(paste("This text is ", tags$span(style="color:red", "red"), sep = ""))
)}
else{
tags$div(HTML(paste("This text is ", tags$span(style="color:blue", "blue"), sep = ""))
)}
Run Code Online (Sandbox Code Playgroud)
有没有人有任何创意?
希望有人可以帮助我.
假设有一个函数"example"就是这样的
##function from a package
example<-function(f){
#does something
cat("step 1 done....")
# etc etc
cat("step 2 done....")
return(some_data_frame)
}
##server ui code
example2<-reactive({
if(input$some_action_button==0)
return()
result<-isolate(example(input$f1))
return(result)
})
output$f2<-renderPrint({
example2()
})
Run Code Online (Sandbox Code Playgroud)
是否有某种方法可以定期将函数中的"cat"输出捕获到renderPrint中?假设这是一个很长的处理功能,用户可以获得一些feedbabk.invalidateLater不适用于已经存在于函数内的东西(至少在我在这里尝试的时候看起来那样).
另外,作为次要问题,以上述方式编写代码会导致renderPrint同时捕获"cat"和data.frame,这可能是因为"返回".
如果有人能指出我正确的方向,那将是最有帮助的!谢谢!
我想构建一个应用程序,在用户键入正确的密码之前,某些选项卡将对用户隐藏。我知道如何使用shinyjs::hideTab:
library(shiny);library(shinyjs)
ui <- fluidPage(useShinyjs(),
navbarPage("hello", id="hello",
tabPanel("home", br(), h3("this is home"),passwordInput("pass", "enter 'password' to see the tabs: "),actionButton("enter", "enter")),
tabPanel("tab2", br(), h4("this is tab2")),
tabPanel("tab3 with a lot of stuff in it", br(), h4("this is tab3"))))
server <- function(input, output, session) {
hideTab("hello", "tab2"); hideTab("hello", "tab3 with a lot of stuff in it")
observeEvent(input$enter, {
if (input$pass == "password"){showTab("hello", "tab2"); showTab("hello", "tab3 with a lot of stuff in it")}})}
shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud)
但是,有一点“东西”。在我的应用程序中,隐藏标签有很多的东西,比如小部件,uiOutputs,图表,图像,global.R文件阅读等的结果是,加载时间更高,在这个应用程序的加载时间(前hideTab指令开始运行),用户实际上会看到隐藏的选项卡,甚至可以单击它们并查看其中的内容。他们保持“可见”状态大约1秒钟,然后被隐藏。
有没有办法让它们在构建UI之前立即隐藏?我更喜欢一个解决方案,而不必将我的所有ui代码放入server.R脚本中...
谢谢
我是闪亮和 stackoverflow 的新手,正在寻找有关我目前遇到的问题的帮助。我正在尝试构建一个闪亮的应用程序,它从用户那里收集一些输入,并根据单击按钮的输入创建可视化。目前,这工作正常,但一个主要问题是,当应用程序第一次加载时,它应该根据默认输入准备可视化。
我正在粘贴一个示例代码,它可以解释我面临的问题:
#loading shiny
library(shiny)
ui<-shinyUI(fluidPage(
titlePanel("Iris Dataset"),
sidebarLayout(
sidebarPanel(
radioButtons("x", "Select X-axis:",
list("Sepal.Length"='a', "Sepal.Width"='b', "Petal.Length"='c', "Petal.Width"='d')),
radioButtons("y", "Select Y-axis:",
list("Sepal.Length"='e', "Sepal.Width"='f', "Petal.Length"='g', "Petal.Width"='h')),
actionButton("action","Submit")
),
mainPanel(
plotOutput("distPlot")
)
)
))
#SERVER.R
library(shiny)
#loading shiny
server<-shinyServer(function(input, output) {
observeEvent(input$action,{
output$distPlot <- renderPlot({if(input$x=='a'){i<-1}
if(input$x=='b'){i<-2}
if(input$x=='c'){i<-3}
if(input$x=='d'){i<-4}
if(input$y=='e'){j<-1}
if(input$y=='f'){j<-2}
if(input$y=='g'){j<-3}
if(input$y=='h'){j<-4}
s <- iris[, i]
k <- iris[, j]
plot(s,k)
})
})
})
shinyApp(ui<-ui, server<-server)
Run Code Online (Sandbox Code Playgroud)
现在,如果您运行此应用程序,您会看到在加载后的第一个屏幕上选择了输入(这是所需的),但仅在单击“提交”按钮后才会出现可视化,这是因为观察者事件。在实际的应用程序中,在单击按钮时捕获输入后正在执行计算。因此,计算仅在单击 actionButton 时触发
有没有办法,我们仍然可以保留“提交”按钮及其观察事件,但会在开始时自动触发可视化或观察事件中执行的操作,即当应用程序第一次加载时。