为了向我的应用程序添加免责声明,我想在应用程序启动时显示一条带有showNotification().
用户不必按下按钮(如下所示)即可显示消息。
shinyApp(
ui = fluidPage(actionButton("show", "Show")),
server = function(input, output) {
observeEvent(input$show, {
showNotification("This is a notification.")
})
})
Run Code Online (Sandbox Code Playgroud) 这里提供了一个在线显示LaTeX方程的解决方案,并提供了一个实时演示
上面提到的在线显示方程式的解决方案是(减少几行代码):
ui.R:
library(shiny)
shinyUI(fluidPage(
title = 'MathJax Examples with in-line equations',
withMathJax(),
# section below allows in-line LaTeX via $ in mathjax. Replace less-than-sign with <
# and grater-than-sign with >
tags$div(HTML("less-than-sign script type='text/x-mathjax-config' greater-than-sign
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
});
less-than-sign /script greater-than-sign
")),
helpText('An irrational number $\\sqrt{2}$
and a fraction $1-\\frac{1}{2}$'),
helpText('and a fact about $\\pi$:$\\frac2\\pi = \\frac{\\sqrt2}2 \\cdot
\\frac{\\sqrt{2+\\sqrt2}}2 \\cdot
\\frac{\\sqrt{2+\\sqrt{2+\\sqrt2}}}2 \\cdots$'),
uiOutput('ex1')
))
Run Code Online (Sandbox Code Playgroud)
server.R:
shinyServer(function(input, output, session) {
output$ex1 <- renderUI({ …Run Code Online (Sandbox Code Playgroud) 在我的 Shiny 应用程序中,有两个输入:观察次数(整数)和颜色(在红色、绿色和蓝色之间选择的字符)。还有一个“GO!” 操作按钮。
使用哪个 Shiny 函数可以:
我更喜欢一个能够为代码提供最大清晰度的解决方案。
请参阅下面我的一项不成功的尝试isolate。
# DO NOT WORK AS EXPECTED
# Define the UI
ui <- fluidPage(
sliderInput("obs", "Number of observations", 0, 1000, 500),
selectInput('color', 'Histogram color', c('red', 'blue', 'green')),
actionButton("goButton", "Go!"),
plotOutput("distPlot")
)
# Code for the server
server <- function(input, output) {
output$distPlot <- renderPlot({
# Take a dependency on input$goButton
input$goButton
# Use isolate() to avoid dependency on input$obs
data <- isolate(rnorm(input$obs))
return(hist(data, col=input$color)) …Run Code Online (Sandbox Code Playgroud) 如RStudio参考文档中所述,闪亮的服务器功能可以选择包含session作为参数(例如function(input, output, session))。会话对象是可用于访问与会话有关的信息和功能的环境。
我从未在我的应用程序中使用此参数,并且可能丢失了一些内容。
该session参数的实际用途是什么?
使用我的简单数据框
> str(dta)
Classes 'tbl_df', 'tbl' and 'data.frame': 54 obs. of 4 variables:
$ year : num 2016 2016 2017 2017 2018 ...
$ severef: num 0.112 0.465 0.11 0.457 0.114 ...
$ package: Factor w/ 3 levels "Baseline","HSS",..: 1 1 1 1 1 1 1 1 1 1 ...
$ run_nb : int 1 2 1 2 1 2 1 2 1 2 ...
Run Code Online (Sandbox Code Playgroud)
跑步时
library(ggplot2)
ggplot(dta, aes(x = year, y = severef, color = package, group = run_nb)) …Run Code Online (Sandbox Code Playgroud) 我有一个日期框架df,看起来像这样:
month values
2012M01 99904
2012M02 99616
2012M03 99530
2012M04 99500
2012M05 99380
2012M06 99103
2013M01 98533
2013M02 97600
2013M03 96431
2013M04 95369
2013M05 94527
2013M06 93783
Run Code Online (Sandbox Code Playgroud)
月份以“M01”、“M02”...等形式书写。现在我想将此列转换为日期格式,有没有办法在 R 中使用 lubridate 来完成此操作?
我还想选择包含每年某个月份的列,例如这些年中仅包含三月的列,最好的方法是什么?