我正在尝试为我的同事提供闪亮的应用程序,而无需他们运行甚至安装R.
所以我看了这个网页 ,发现这句话:
如果您熟悉Web托管或可以访问IT部门,则可以自己托管您的Shiny应用程序.
在" 共享为网页 "部分下.
我怎样才能做到这一点?
问题是我的公司必然会受到关于网络托管和安全等的某些限制,并且不会(现在)支付闪亮的服务器专业版.
但上面的句子让我希望自己设置一些东西来说服他们.
我正在试图找出如何使用downloadButton来保存有光泽的情节.包中的示例演示了downloadButton/downloadHandler以保存.csv.我将基于此制作一个可重现的示例.
对于 ui.R
shinyUI(pageWithSidebar(
headerPanel('Downloading Data'),
sidebarPanel(
selectInput("dataset", "Choose a dataset:",
choices = c("rock", "pressure", "cars")),
downloadButton('downloadData', 'Download Data'),
downloadButton('downloadPlot', 'Download Plot')
),
mainPanel(
plotOutput('plot')
)
))
Run Code Online (Sandbox Code Playgroud)
对于 server.R
library(ggplot2)
shinyServer(function(input, output) {
datasetInput <- reactive({
switch(input$dataset,
"rock" = rock,
"pressure" = pressure,
"cars" = cars)
})
plotInput <- reactive({
df <- datasetInput()
p <-ggplot(df, aes_string(x=names(df)[1], y=names(df)[2])) +
geom_point()
})
output$plot <- renderPlot({
print(plotInput())
})
output$downloadData <- downloadHandler(
filename = function() { paste(input$dataset, '.csv', sep='') },
content = function(file) { …Run Code Online (Sandbox Code Playgroud) 我最近了解到R Shiny程序默认情况下对文件上传施加了最大大小限制(我不知道大小究竟是什么,但我猜它是5,000 KB).我想删除这个限制.我怎么能这样做,对于用户上传的大小有什么一般的经验法则?
此外,这是另一个注意事项,但相关:如何通过用户BY会话保存输入?例如,应用程序中会有一个文件提示符,用户可以在其中上传文件.然后,当用户选择要显示的文件时,他可以在他上传的文件中进行选择.如果他退出会话,清单就会清除.
我想要两个不同的事件来触发我的应用程序中各种图表/输出所使用的数据的更新.一个是单击按钮(input$spec_button),另一个是点击点上的点(mainplot.click$click).
基本上,我想同时列出两者,但我不知道如何编写代码.这就是我现在拥有的:
在server.R中:
data <- eventReactive({mainplot.click$click | input$spec_button}, {
if(input$spec_button){
# get data relevant to the button
} else {
# get data relevant to the point clicked
}
})
Run Code Online (Sandbox Code Playgroud)
但if-else子句不起作用
Error in mainplot.click$click | input$spec_button :
operations are possible only for numeric, logical or complex types
- >我可以使用某种动作组合器功能用于该mainplot.click$click | input$spec_button子句吗?
我有一个闪亮的服务器版本0.4.0,我希望有4个小textInput框看起来像这样:
x-min x-max y-min y-max
[...] [...] [...] [...]
Run Code Online (Sandbox Code Playgroud)
他们现在看起来像这样:
x-min
[...................]
x-max
[...................]
y-min
[...................]
y-max
[...................]
Run Code Online (Sandbox Code Playgroud)
使用此代码:
textInput(inputId="xlimitsmin", label="x-min", value = 0.0),
textInput(inputId="xlimitsmax", label="x-max", value = 0.5),
textInput(inputId="ylimitsmin", label="y-min", value = 0.5),
textInput(inputId="ylimitsmax", label="y-max", value = 1.0),
Run Code Online (Sandbox Code Playgroud)
任何想法如何实现这一目标?
编辑:我在代码的其他地方成功地改变了这样的事情:
<style type="text/css">select#yaxis4 { height: 280px; width: 500px; }</style>
[... which links to this later on in the page...]
<label class="control-label" for="yaxis4">Y-Axis</label>
<select id="yaxis4" multiple="multiple">
Run Code Online (Sandbox Code Playgroud)
这就是那些不起作用的东西:
<style type="text/css">select#xlimitsmax { display: inline-block; max-width: 50px; }</style>
[... which links to...]
<label>x-max</label>
<input …Run Code Online (Sandbox Code Playgroud) 在一个闪亮的应用程序(由RStudio),在服务器端,我有一个反应,通过解析a的内容返回变量列表textInput.然后在selectInput和/或中使用变量列表updateSelectInput.
我不能让它发挥作用.有什么建议?
我做了两次尝试.第一种方法是outVar直接使用反应selectInput.第二种方法是使用反应性outVar在updateSelectInput.两者都不起作用.
shinyServer(
function(input, output, session) {
outVar <- reactive({
vars <- all.vars(parse(text=input$inBody))
vars <- as.list(vars)
return(vars)
})
output$inBody <- renderUI({
textInput(inputId = "inBody", label = h4("Enter a function:"), value = "a+b+c")
})
output$inVar <- renderUI({ ## works but the choices are non-reactive
selectInput(inputId = "inVar", label = h4("Select variables:"), choices = list("a","b"))
})
observe({ ## doesn't work
choices <- outVar()
updateSelectInput(session …Run Code Online (Sandbox Code Playgroud) 我想使用一个renderText()命令输出多行文本.但是,这似乎不可能.例如,从闪亮的教程中我们截断了代码server.R:
shinyServer(
function(input, output) {
output$text1 <- renderText({paste("You have selected", input$var)
output$text2 <- renderText({paste("You have chosen a range that goes from",
input$range[1], "to", input$range[2])})
}
)
Run Code Online (Sandbox Code Playgroud)
和代码ui.R:
shinyUI(pageWithSidebar(
mainPanel(textOutput("text1"),
textOutput("text2"))
))
Run Code Online (Sandbox Code Playgroud)
基本上打印两行:
You have selected example
You have chosen a range that goes from example range.
Run Code Online (Sandbox Code Playgroud)
是否有可能在两行合并output$text1,并output$text2成为一个代码块?到目前为止,我的努力都失败了,例如
output$text = renderText({paste("You have selected ", input$var, "\n", "You have chosen a range that goes from", input$range[1], "to", input$range[2])})
Run Code Online (Sandbox Code Playgroud)
有人有主意吗?
组织更大的Shiny应用程序的最佳实践是什么?
我认为最好的R实践也适用于Shiny.
这里讨论最佳R实践:如何组织大型R程序
链接到谷歌的R风格指南:风格指南
但是,我可以采用什么样的Shiny上下文中的独特提示和技巧,使我的Shiny代码看起来更好(更具可读性)?我想的是:
server.R这部分应采购?例如,如果我正在使用,navbarPage并且tabsetPanel在tabPanel添加几个UI元素后,我的每个代码都开始变得非常混乱.
示例代码:
server <- function(input, output) {
#Here functions and outputs..
}
ui <- shinyUI(navbarPage("My Application",
tabPanel("Component 1",
sidebarLayout(
sidebarPanel(
# UI elements..
),
mainPanel(
tabsetPanel(
tabPanel("Plot", plotOutput("plot")
# More UI elements..
),
tabPanel("Summary", verbatimTextOutput("summary")
# And some more...
),
tabPanel("Table", tableOutput("table")
# And...
)
)
)
)
),
tabPanel("Component 2"),
tabPanel("Component 3")
))
shinyApp(ui = ui, server = server)
Run Code Online (Sandbox Code Playgroud)
为了组织ui.R …
冒着使用mods"太宽泛的问题"锤子的风险,我想问一下,鉴于大量的交互式R Shiny工具和软件包的出现,你什么时候使用哪一个?
闪亮 - 对我来说,只有你的项目需要从闪亮的服务器运行,但似乎是最好的选择.
shinydashboard - 闪亮,但有很好的价值框标注.
flexdashboard - 在Rmd中写出来.什么让你直接闪亮没有?也许,如果您愿意传递数据,可以通过电子邮件发送给客户吗?我一直在玩,flexdashboard但它无法使用数据表(库(DT))让我觉得它需要更多的迭代.
看看其他答案,我并不是唯一一个问这个问题的人.
创作者在那里提供了很多画廊来展示他们的包裹/进场,但是你怎么知道要走哪条路?
使用一个优于另一个的明显优势是什么?
我正在写一个Shiny应用程序,用于可视化我公司的保险福利计划.这是我想要发生的事情:
selectInput或sliderInput哪个用户将选择他们的医疗计划中的个人数量这是我当前的ui.R文件,带有硬编码输入,模拟一个四口之家:
shinyUI(pageWithSidebar(
headerPanel("Side by side comparison"),
sidebarPanel(
selectInput(inputId = "class", label = "Choose plan type:",
list("Employee only" = "emp", "Employee and spouse" = "emp_spouse",
"Employee and child" = "emp_child", "Employee and family" = "emp_fam")),
sliderInput(inputId = "ind1", label = "Individual 1",
min = 0, max = 20000, value = c(0, 2500), step = 250),
sliderInput(inputId = "ind2", label = "Individual 2",
min = 0, max = 20000, value = …Run Code Online (Sandbox Code Playgroud)