对不起,如果这是一个常见问题,但它让我发疯。我需要将 actionButton 添加到触发文件保存的 Shiny UI。实际的文件保存命令取决于 tabPanel 的哪个选项卡打开,我可以通过 tabPanel id 获取该信息。我遇到的问题是访问 actionButton 的状态并在之后重置它。
在 ui.r 中,我有这样的东西:
shinyUI(fluidPage(
titlePanel("myTitle"),
sidebarLayout(
sidebarPanel("",
actionButton("save", "Save File"),
# test to make sure the button is working
verbatimTextOutput("sb") # it increments when clicked
)
)
))
Run Code Online (Sandbox Code Playgroud)
在 server.r 中,我正在尝试这样做:
shinyServer(function(input, output) {
# test to make sure the button is working
output$sb <- renderPrint({ input$save }) # increments when clicked
# here is the problem code:
if(input$save > 0) { # button was clicked, so...
input$save …Run Code Online (Sandbox Code Playgroud) 当我将鼠标悬停在图表中的一个点上时,我希望显示高度或重量的值。我已经尝试通过使用plotly包和此链接的示例来完成这项工作。但是我遇到了各种各样的错误,我不知道如何使它工作。
我已经包含了我的整个代码,所以我希望有人可以帮助我解决这个问题。
library("shiny")
library("ggplot2")
library('readxl')
library('gridExtra')
ui<- fluidPage(
titlePanel("Animals"),
sidebarLayout(
sidebarPanel(
helpText("Create graph of height and/or weight animals"),
selectInput("location",
label = "Choose a location",
choices = list("New York"="New York", "Philadelphia" = "Philadelphia"),
selected = "New York"),
uiOutput("animal"),
checkboxGroupInput("opti",
label = "Option",
choices = c("weight", "height"),
selected = "weight")
),
mainPanel(plotOutput("graph"))
))
server <- function(input, output){
animal <- read_excel('data/animals.xlsx', sheet =1)
var <- reactive({
switch(input$location,
"New York" = list("Cat1", "Dog2"),
"Philadelphia"= list("Cat4","Dog3"))
})
output$animal <- renderUI({
checkboxGroupInput("anim", …Run Code Online (Sandbox Code Playgroud) 我正在尝试将 pdf 上传到闪亮的。如果pdf文件来自互联网,以下代码运行良好:
library(shiny)
runApp(list(
ui = fluidPage(
sidebarLayout(
sidebarPanel(
h5("use case - embed a pdf user guide in the app - embed as a local pdf or from web URL")
),
mainPanel(
tabsetPanel(
# using iframe along with tags() within tab to display pdf with scroll, height and width could be adjusted
tabPanel("Reference",
tags$iframe(style="height:800px; width:100%; scrolling=yes",
src="https://cran.r-project.org/doc/manuals/r-release/R-intro.pdf")),
tabPanel("Summary"),
tabPanel("Plot")
)
))
),
server = function(input, output,session){}
))
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试上传保存在桌面(也是工作目录)中的 pdf 时,我看不到 pdf 文件。我曾经src="example.pdf"替换过网络文件链接。正如其他一些 StackOverflow 帖子所建议的那样,我将 pdf 文件保存在名为 的文件夹中 …
我是闪亮的新手。当我制作我的项目时,我需要在服务器端隐藏dashboardHeader。
在 Shinydashboard 网站上,我找到了代码dashboardHeader(disable = TRUE)。我试过这个,但它不起作用。
但是,我尝试使用shinyjs 来解决问题。
<code>
library(shiny)
library(shinydashboard)
library(shinyjs)
ui <- dashboardPage(
dashboardHeader(
extendShinyjs(text = 'shinyjs.hidehead = function(params) {
$("header").addClass("sidebar-collapse") }'),
),
dashboardSidebar(),
dashboardBody(
actionButton("button","hide_header",width = 4 )
)
)
server <- function(input, output) {
observeEvent(input$button, {
js$hidehead()
})}
shinyApp(ui, server)</code>
Run Code Online (Sandbox Code Playgroud)
我想你已经知道了,它仍然没有奏效。
对我的情况有什么想法吗?
ui <- dashboardPage(
dashboardHeader(title = "Sales"),
dashboardSidebar(),
dashboardBody(
tags$style(HTML(".box-header{background:#d2d2d2; color:#d83000; text-align:center;}")),
shinyUI(fluidPage(
fluidRow(
box(fluidRow(column(width = 12,
valueBox(1000,"Total Sales", width = 2),
valueBox(500,"Existing Sales", width = 2),
valueBox(300,"New Sales", width = 2),
valueBox(100,"Lost Sales", width = 2),
valueBox(100,"Unclassified Sales", width = 2))),
fluidRow(column(width=12, offset = 2,valueBox(250, "within existing sales", width = 2))),
width = 12, title = tags$b("BUSINESS MODEL"), solidHeader = TRUE)
)#,
#box(title = "Title", height = 20, width = 8, solidHeader = TRUE)
))))
# Define server logic required …Run Code Online (Sandbox Code Playgroud) 我在新的闪亮 R 中,但水平滚动有问题。这是我的代码。
output$sbirx.view <- DT::renderDataTable(
{
dataset.filter()
}, options = list(
searching = TRUE,
autoWidth=TRUE,
paging=FALSE,
scrollX=TRUE,
scrollY="500px",
scrollCollapse = TRUE,
fixedHeader=TRUE,
fixedColumns=list(leftColumns = 2, rightColumns = 0,
heightMatch = 'none')
),
rownames=FALSE,
class = 'cell-border stripe',
extensions = c('FixedColumns',"FixedHeader")
Run Code Online (Sandbox Code Playgroud)
)
数据有 79 列,我可以选择要显示的列数。前 2 个 leftcolumns(DISEASE 和 PRODUCT)应该是固定的,如果你只显示 3 列,表格看起来像这样。但是,如果我选择适合屏幕的几列,则没有问题。
疾病产品 疾病产品 2010-11 疾病1 产品1 疾病1 产品1 25,000 疾病1 产品2 疾病1 产品2 15,000 疾病1 产品3 疾病1 产品3 5,000
有没有办法使用任何选项来解决这个问题?
感谢您的时间和帮助。
我想明白为什么使用时,下表是不会自动更新invalidateLater()的内部observeEvent()。我准备了以下程序来说明我的问题,“mytable2”使用reactiveTimer()并确实产生了所需的输出,但是“mytable”使用invalidateLater()并且不会自动更新,除非我单击“更新”按钮。为什么?
library(shiny)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
actionButton("update", "Update")
),
mainPanel(
column(6, tableOutput('mytable')),
column(6, tableOutput('mytable2'))
)
)
)
server <- function(input, output) {
values <- reactiveValues(df = RenderMyTable())
observeEvent(invalidateLater(1000), {
values$df <- RenderMyTable() # This does not update after 1 sec
})
observeEvent(input$update, {
values$df <- RenderMyTable() # This does update upon clicking
})
output$mytable <- renderTable(values$df) # Depends on reactiveValues
autoInvalidate <- reactiveTimer(1000)
output$mytable2 <- renderTable({
autoInvalidate()
RenderMyTable() # >This does …Run Code Online (Sandbox Code Playgroud) 当我在 R 包结构中使用闪亮时,我的图像没有显示。
在我的 R 目录中,我有一个文件 myApp.R,其大纲如下:
@param1
myFunction = function(param1){
sidebar <- dashboardSidebar(...)
body <- dashboardBody(...)
ui <- dashboardPage(...)
server <- function(input, output, session) { img(src='Figure1.png')}
shinyApp(ui = ui, server = server)
}
Run Code Online (Sandbox Code Playgroud)
我尝试在 R/www 和 inst/www 中使用 Figure1.png,但是当我运行 myFunction(param1) 时,这两个位置似乎都没有创建数字。它将创建通用应用程序 - 但图像将不存在。
这个问题有简单的解决方法吗?谢谢你。
有一个选项可以在datatables.net网站上添加自定义按钮。如何在R Shiny应用中进行编码?一个按钮和观察者的基本R代码示例将非常有趣。
这是来自https://datatables.net/extensions/buttons/examples/initialisation/custom.html的 JS代码
$(document).ready(function() {
$('#example').DataTable( {
dom: 'Bfrtip',
buttons: [
{
text: 'My button',
action: function ( e, dt, node, config ) {
alert( 'Button activated' );
}
}
]
} );
} );
Run Code Online (Sandbox Code Playgroud)
谢谢 !
我编写了一个小应用程序,您可以在其中看到一个单选按钮,您可以使用它在绘图图表和渲染表格之间切换。有用。之后我阅读了有关模块的 Shiny 文档并最终得到了这个应用程序:
我的应用程序R
library(shiny)
ui <- fluidPage(
fluidRow(
column(6,
chartTableSwitchUI("firstUniqueID")
)
)
)
server <- function(input, output) {
callModule(chartTableSwitch, "firstUniqueID")
}
shinyApp(ui = ui, server = server)
Run Code Online (Sandbox Code Playgroud)
我编写了一个 globar.R ,如下所示:
library(shiny)
library(plotly)
#define a simple dataframe for module example
X <- c("a", "b", "c")
Y <- c(1,2,3)
df <- data.frame(X,Y)
#UI function for first module
chartTableSwitchUI <- function(id){
ns <- NS(id)
tagList(
radioButtons("rb1", "View", choices = c(ns("Chart"), ns("Table")),
selected = "Chart", inline = TRUE),
conditionalPanel(
condition = "input.rb1 == …Run Code Online (Sandbox Code Playgroud) 我正在将csv文件上传到一个闪亮的过滤器并尝试从所选列中绘制ggplot.
output$plot = renderPlot(
{
df <- data_set()
gp <- NULL
if (!is.null(df)){
xv <- input$xaxisGrp
yv <- input$yaxisGrp
if (!is.null(xv) & !is.null(yv)){
if (sum(xv %in% names(df))>0){ # supress error when changing files
mdf <- melt(df,id.vars=xv,measure.vars=yv)
gp <- ggplot(data=mdf) +
geom_point(aes_string(x=xv,y="value",color="variable"))+
geom_smooth(method="lm")+
theme(axis.text.x=element_text(angle=45, hjust=1))+
theme_hc() +
scale_colour_hc()+theme(legend.title=element_blank())
}
}
}
return(gp)
}
Run Code Online (Sandbox Code Playgroud)
我可以创建图表但是当我尝试添加时
+geom_smooth(method="lm")
Run Code Online (Sandbox Code Playgroud)
我没有得到任何想法可能发生的lm线?
给定这样的数据集:
dput(df)
structure(list(load = c(1L, 18L, 36L, 72L, 108L, 144L, 216L),
throughput = c(64.9, 995.9, 1652.4, 1853.2, 1828.9, 1775,
1702.2)), .Names = c("load", "throughput"), class …Run Code Online (Sandbox Code Playgroud) 嗨,大家好,我已经尝试了几个星期,但我无法完成它.R传单的在线资源也不够.真的需要完成这件事.
请帮忙,非常感谢你.
ui.R - >
library(shiny)
library(ggmap)
library(leaflet)
shinyUI(bootstrapPage(
leafletOutput("map"),
br(),
verbatimTextOutput("out")
)
)
Run Code Online (Sandbox Code Playgroud)
server.R - >
library(shiny)
library(ggmap)
library(leaflet)
shinyServer(function(input, output, session) {
output$map <- renderLeaflet({
p <- input$map_click
if(is.null(p)){
leaflet() %>% setView(lng = -43.1729, lat = -22.9068, zoom = 11) %>%
addTiles(options = providerTileOptions(noWrap = TRUE))
}
else{
address <- revgeocode(c(p$lng,p$lat))
leaflet() %>% setView(lng = p$lng, lat = p$lat, zoom = 16) %>%
addTiles(options = providerTileOptions(noWrap = TRUE)) %>%
addCircles(p$lng, p$lat, weight = 1, radius = 100, color …Run Code Online (Sandbox Code Playgroud) 如何根据复选框输入创建动态绘图,绘图数量应根据所选复选框的名称增加和减少。